[R] How to use the paste function to create an already used variable

Henrique Dallazuanna wwwhsd at gmail.com
Wed Mar 24 14:35:01 CET 2010


Try this:

Data <- lapply(ls(pattern = 'data[0-9]'), get)

Data[[1]] is data1
Data[[2]] is data2
....
etc.

2010/3/24 "Biedermann, Jürgen" <juergen.biedermann at charite.de>:
> Hi there,
>
> I have the following problem
>
> Four data frames exist:
>
> data1
> data2
> data3
> data4
>
> Now I want to write a loop and temporarily store the data1, data2, data3,
> data4 in a variable called data.
> I tried the following...
>
> for (i in 1:4) {
> Data <- paste("data",i,sep="")
> ...
> ..
> }
>
>
> but it doesn't function. I think the problem is the definition of the mode
> of the pasted variable.
>
> Could anyone help me?
> Thanks
>
> Greetings
> Jürgen
>
> ______________________________________________
> 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.
>



-- 
Henrique Dallazuanna
Curitiba-Paraná-Brasil
25° 25' 40" S 49° 16' 22" O



More information about the R-help mailing list