[R] Generate object names from variables

Georg Otto georg.otto at tuebingen.mpg.de
Fri Jul 14 16:57:05 CEST 2006


I want to generate object names out of variables in a sort of variable

first i generate some vectors and an empty list:

> vector.a<-c("a","b")
> vector.b<-c("c","d")
> vector.c<-c("e","f")
> vectors<-c("vector.a", "vector.b", "vector.c")
> vectors
[1] "vector.a" "vector.b" "vector.c"

> vectorlist<-list()

What I would then like to do is to generate elements of the list by
using variables, somehow like this (does not work):

>for (i in vectors) {
+ list$i<-i
+ }

To end up with a list like this:

> list
 [1] "a" "b"
 [1] "c" "d"
 [1] "e" "f"

Any hint will be appreciated.



More information about the R-help mailing list