[R] Generate object names from variables

From: Georg Otto <georg.otto_at_tuebingen.mpg.de>
Date: Sat 15 Jul 2006 - 00:57:05 EST


Hi,

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

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

$vector.a
 [1] "a" "b"
$vector.b
 [1] "c" "d"
$vector.c

 [1] "e" "f"

Any hint will be appreciated.

Cheers,

Georg



R-help@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 Received on Sat Jul 15 01:00:48 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Sat 15 Jul 2006 - 02:15:00 EST.

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