[R] How do I generate multiple (similar) objects within R?

Dieter Menne dieter.menne at menne-biomed.de
Thu Nov 20 17:11:34 CET 2008

Nicklas Pettersson <Nicklas.Pettersson <at> stat.su.se> writes:

> I wonder if anyone knows how to generate a list of objects, e.g. ten 
> vectors with names: vect1, vect2, ... , vect10.
> My own idea was to use something like:
>     for (i in 1:10)
>     print(paste("vect", i,"<-NULL",sep=""))

for (i in 1:10)
  eval(parse(text=paste("vect", i,"<-NULL",sep="")))
But better use a list or vector for what you are trying to do. Note that 
the  "list of objects" is not exactly what you intended with your example
(which otherwise is nice, because it shows clearly what did not work).


More information about the R-help mailing list