Re: [R] Applying rbind() to a sequence of data frame names

From: jim holtman <jholtman_at_gmail.com>
Date: Tue, 01 Apr 2008 11:22:32 -0500

Will this do it for you:

> ds1 <- data.frame(x=c(1,2,3,4), y=c(5,6,7,8))
> ds2 <- data.frame(x=c(9,10,11,12), y=c(13,14,15,16))
> ds3 <- data.frame(x=c(1,2,3,4), y=c(5,6,7,8))
> ds4 <- data.frame(x=c(9,10,11,12), y=c(13,14,15,16))
> x.n <- c('ds1','ds2','ds3','ds4')
>
> # create a list of data frames
> x.list <- lapply(x.n, get)
>
> # combine into a single dataframe
> do.call(rbind, x.list)

    x y
1 1 5
2 2 6
3 3 7
4 4 8
5 9 13
6 10 14
7 11 15
8 12 16
9 1 5
10 2 6
11 3 7
12 4 8
13 9 13
14 10 14
15 11 15
16 12 16
>

On 4/1/08, Hans W. Borchers <hwborchers_at_gmail.com> wrote:
> I have a set of data frames ds1, ds2, ... each having the same columns
> and column names:
>
> ds1 <- data.frame(x=c(1,2,3,4), y=c(5,6,7,8))
> ds1 <- data.frame(x=c(9,10,11,12), y=c(13,14,15,16))
> ...
>
> and I would like to combine them into just one data frame like
>
> ds <- rbind(ds1, ds2, ...)
>
> Because there are so many of them, I will have to use a character array
>
> nms <- c("ds1", "ds2", ...)
>
> How can I use this character array to generate a command using rbind()
> on all of these data frames at once.
>
> I tried to apply eval() somehow, but did not come up with the right idea.
>
> Thanks
>
> ______________________________________________
> R-help_at_r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Tue 01 Apr 2008 - 17:34:35 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Tue 01 Apr 2008 - 18:30:25 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive