[R] binding data.frames with sequential names

Phil Spector spector at stat.berkeley.edu
Tue Dec 14 01:23:16 CET 2010


Tony -
    Try

do.call(rbind,lapply(paste('X',1:i,sep=''),get))

(You've created the names, but you need to tell R to use 
the objects which have those names.  That's what get() does.)

<soapbox>
You'd probably be better served by putting the 
data frames you create into a list as they are created, 
rather than giving each one an individual name.  That
way you could simply use  do.call(rbind,list-of-dataframes) .
</soapbox>

 					- Phil Spector
 					 Statistical Computing Facility
 					 Department of Statistics
 					 UC Berkeley
 					 spector at stat.berkeley.edu



On Mon, 13 Dec 2010, Anthony Fristachi wrote:

> Hello,
>
> I have data frames X1 to X19
>
> I want a simple way to bind them as the next run(s) will generate many
> more sequential data frames.
>
> I tried the following with i = 19:
>
>> my.list <- as.list(paste("X",1:i,sep=""))
>
>> new.data <- do.call("rbind", my.list)
>
>> new.data
>      [,1]
> [1,] "X1"
> [2,] "X2"
> [3,] "X3"
> [4,] "X4"
> [5,] "X5"
> [6,] "X6"
> [7,] "X7"
> [8,] "X8"
> [9,] "X9"
> [10,] "X10"
> [11,] "X11"
> [12,] "X12"
> [13,] "X13"
> [14,] "X14"
> [15,] "X15"
> [16,] "X16"
> [17,] "X17"
> [18,] "X18"
> [19,] "X19"
>
>
> Thank you
>
> Tony
>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
> Tony Fristachi
> Human Health and Ecological Risk Assessor
> Portage, Inc.
> 335 Central Park Square
> Los Alamos, NM 87544
> office: 505.663.1526 / fax: 505.662.7340
> cell: 505.412.8442
> www.portageinc.com
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list