R: Converting a list of data frames into one data frame
Posted
by JD Long
on Stack Overflow
See other posts from Stack Overflow
or by JD Long
Published on 2010-05-17T17:38:24Z
Indexed on
2010/05/17
18:20 UTC
Read the original article
Hit count: 234
I have code that at one place ends up with a list of data frames which I really want to convert to a single big data frame.
I got some pointers from an earlier question which was trying to do something similar but more complex.
Here's an example of what I am starting with (this is grossly simplified for illustration):
listOfDataFrames <- NULL
for (i in 1:100) {
listOfDataFrames[[i]] <- data.frame(a=sample(letters, 500, rep=T),
b=rnorm(500), c=rnorm(500))
}
I am currently using this:
df <- do.call("rbind", listOfDataFrames)
*EDIT*
whoops. In my haste to implement what I had "learned" in a previous question I totally screwed up. Yes, the unlist() is just plain wrong. I'm editing that out of the question above.
© Stack Overflow or respective owner