I have a list of data frames and I want to concatenate them into a
single data frame, basically appending all of the data frames to each
other (they are all the same shape, in terms of columns). I'm looking
for a nice way to do that. I can of course just consecutively rbind
them to a "master" dataframe, but I have 22,000 such data frames, each
with a few hundred rows, so this process takes a good while. Should be
simple, I imagine....
Here is a toy data structure.
j <- list()
for (i in letters[1:26]) {j[[i]] <-
data.frame(rep(i,25),matrix(rnorm(250),nrow=25))}
Thanks.
Sean
I do not know of a better way than to do something like
do.call("rbind",
listOfDataFrame). This will take a while because rbind.data.frame needs to
check and make sure the result is a valid data.frame (e.g., rownames need to
be unique). If all the columns are of the same type, you might find it
faster to coerce to matrices, rbind, then coerce back to data.frame.
HTH,
Andy
> From: Sean Davis
>
> I have a list of data frames and I want to concatenate them into a
> single data frame, basically appending all of the data frames to each
> other (they are all the same shape, in terms of columns).
> I'm looking
> for a nice way to do that. I can of course just consecutively rbind
> them to a "master" dataframe, but I have 22,000 such data
> frames, each
> with a few hundred rows, so this process takes a good while.
> Should be
> simple, I imagine....
>
> Here is a toy data structure.
> j <- list()
> for (i in letters[1:26]) {j[[i]] <-
> data.frame(rep(i,25),matrix(rnorm(250),nrow=25))}
>
> Thanks.
>
> Sean
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
>
>
Sean --
You want do.call("rbind", your.list.of.data.frames). do.call is
helpful in
a lot of situations when you want to construct a list of arguments and then
apply a function.
Hope this helps,
Matt Wiener
-----Original Message-----
From: r-help-bounces at stat.math.ethz.ch
[mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Sean Davis
Sent: Thursday, October 28, 2004 9:30 AM
To: r-help
Subject: [R] Quick data-manipulation question
I have a list of data frames and I want to concatenate them into a
single data frame, basically appending all of the data frames to each
other (they are all the same shape, in terms of columns). I'm looking
for a nice way to do that. I can of course just consecutively rbind
them to a "master" dataframe, but I have 22,000 such data frames, each
with a few hundred rows, so this process takes a good while. Should be
simple, I imagine....
Here is a toy data structure.
j <- list()
for (i in letters[1:26]) {j[[i]] <-
data.frame(rep(i,25),matrix(rnorm(250),nrow=25))}
Thanks.
Sean
______________________________________________
R-help at stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
How about do.call("rbind", j) ?
Hadley
On Thu, 28 Oct 2004 09:29:46 -0400, Sean Davis <sdavis2 at mail.nih.gov>
wrote:> I have a list of data frames and I want to concatenate them into a
> single data frame, basically appending all of the data frames to each
> other (they are all the same shape, in terms of columns). I'm looking
> for a nice way to do that. I can of course just consecutively rbind
> them to a "master" dataframe, but I have 22,000 such data frames,
each
> with a few hundred rows, so this process takes a good while. Should be
> simple, I imagine....
>
> Here is a toy data structure.
> j <- list()
> for (i in letters[1:26]) {j[[i]] <-
> data.frame(rep(i,25),matrix(rnorm(250),nrow=25))}
>
> Thanks.
>
> Sean
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html
>