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 8402813
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:10:11+00:00 2026-06-09T22:10:11+00:00

How can I add a data frame to a list in R? I am

  • 0

How can I add a data frame to a list in R? I am trying the following code.

First, I create a data frame from a csv file (any csv file will do)

> a <- read.csv(csvFile)
> class(a)
[1] "data.frame"

so, I have a data frame called “a”. Now I create a list with one character item as shown below

> b <- list("hello world")

Now, I append my data frame “a” to the list b as shown below

> b[[length(b)+1]] <- a
> class(b)
[1] "list"
> length(b)
[1] 2

so far so good. List b now has 2 items (the character string “hello world” and the data frame a). Now the piece that puzzles me is the following code

> class(b[2])
[1] "list"

why is class(b[2]) showing up as a list instead of a data frame? I want to be able to add my data frame “a” to the list “b” without having a be converted implicitly into a list. Can anyone help me understand how to do this?

  • 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-09T22:10:13+00:00Added an answer on June 9, 2026 at 10:10 pm

    This is documented in ?"[" (or ?Extract), in the “Recursive (list-like) objects” section (emphasis added):

    Indexing by ‘[’ is similar to atomic vectors and selects a list of
    the specified element(s).

    Both ‘[[’ and ‘$’ select a single element of the list.

    Since b[2] returns a list, you want to use [[, i.e. b[[2]].

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written the following code: library(ggplot2) data <- structure(list(x = c(1L, 6L, 3L,
Lets have the following dataframe inside R: df <- data.frame(sample=rnorm(1,0,1),params=I(list(list(mean=0,sd=1,dist=Normal)))) df <- rbind(df,data.frame(sample=rgamma(1,5,5),params=I(list(list(shape=5,rate=5,dist=Gamma))))) df
Is there a way that I can add non-static data to dataannotation attributes (either
is it possible to add custom data to the results so it can be
How can I use data binding on a details form to add a new
Two questions. First question is I'm trying to create a simple form that when
Having just spent an hour chasing a 'matrix vs data.frame' bug in my code,
I have a data frame in R, and I'd like to add dummy variables
I can add and remove the last line in my dynamic form and calculate
I can add a normal rightBarButton to my navigation without a problem but now

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.