Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8522529
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T07:08:47+00:00 2026-06-11T07:08:47+00:00

So I initialize a list, which I want to fill with dataframes: listz <-

  • 0

So I initialize a list, which I want to fill with dataframes:

listz <- vector("list",2)

I also want to keep the dataframes’ names around, so I assign them:

listzNames <- c("frame1","frame2")
names(listz) <- listzNames

The problem is, with every reassignment I make to the dataframes, the names go NULL:

listz <- list(data.frame("id" = 1:3, "hat" = 1:3),
           data.frame("id" = 4:6, "hat" = 4:6))

> names(listz)
NULL

I know why this happens, but what would be a neat alternative to reassigning the names at every dataframe reassignment?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T07:08:49+00:00Added an answer on June 11, 2026 at 7:08 am

    When you assign

    listz <- list(data.frame("id" = 1:3, "hat" = 1:3),
               data.frame("id" = 4:6, "hat" = 4:6))
    

    You are replacing the object formerly defined as listz, it is a new object, unrelated to any previous objects of that name.

    Therefore is no need to initialize the list in this case

    you have (at least) four options for setting names of a list

    option 1 – setNames

    # Option 1 - using setNames
    listz <- setNames(list(data.frame("id" = 1:3, "hat" = 1:3),
               data.frame("id" = 4:6, "hat" = 4:6)), listzNames)
    

    option 2 – name as you go

    # Option 2 - naming the list as you go
    listz <- list(frame1 = data.frame("id" = 1:3, "hat" = 1:3),
               frame2 = data.frame("id" = 4:6, "hat" = 4:6))
    

    option 3 – Hmisc and llist

    # If your data.frames already exist
    # use the llist function in Hmisc, which names the list
    # using the names of the object in each element
    library(Hmisc)
    frame1 <- data.frame("id" = 1:3, "hat" = 1:3)
    frame2 <- data.frame("id" = 4:6, "hat" = 4:6)
    
    listz <- llist(frame1,frame2)
    

    option 4 – prexisting using setNames and get

    # if your data.frames already exist in the global environment then
    # you can use
    listz <- setNames(lapply(listzNames, get),listzNames)
    

    option 5 initializing the list (I don’t like this)

    listz <- vector("list",2)
    names(listz) <- listzNames
    listz[[1]] <- data.frame("id" = 1:3, "hat" = 1:3)
    listz[[2]] <- data.frame("id" = 4:6, "hat" = 4:6)
    

    I don’t like this option, it requires more typing and therefore more chance of errors!

    Note about lapply

    lapply will preserve any names

    lapply(listz,head,n=1)
    
    #$frame1
    #  id hat
    #1  1   1
    #
    #$frame2
    #  id hat
    #1  4   4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to LINQ. playerData is a list<DataAccess.Team> and I want to initialize
I have a variable which is the head to a linked list. I want
I have a list of user groups which I want to display in JSF
I'm trying to initialize an array in my constructor's intialization list, and I want
In c# I can initialize a List at creation time like var list =
More specifically, is List(T)(IEnumerable(T)) thread-safe if the IEnumerable used to initialize the list is
//initialize the people data list - (void)initializePeopleListFromJson:(CLLocationCoordinate2D)coordinate auraId:(NSString *)auraId { //initialize the NSMutableArray list
I create a linked list dynamically and initialize the first node in main(), and
I've got a public List<FriendProfile> friends = new ArrayList<FriendProfile>(); . I initialize the friends
I want to have some kind of single list that is initialized in a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.