[R] How to use a for loop to generate two sequences

Gabor Grothendieck ggrothendieck at gmail.com
Fri Jun 30 00:34:13 CEST 2006


A vector of character strings:

  nm <- paste("test", 1:1000, sep = "")

A list whose components are the objects: test1, test2, ...

  lapply(nm, get)

or if you do it this way the list will have 'test1', 'test2', ... as the
component names:

  L <- sapply(paste("test", 1:1000, sep = ""), get, simplify = FALSE)

and then

  names(L)

gives the vector of names.


Also note that

  apropos("^test[0-9]+")

will give a vector of object names corresponding to objects
 in the current workspace whose names
are "test" followed by a number.

On 6/29/06, Xiaohua Dai <ecoinformatics at gmail.com> wrote:
> Hi R users,
>
> Hope the question is not too simple:
>
> How to use a for loop to generate two lists as below:
>
> testlist <- list(test1, test2, ..., test1000)
> stringlist <- list("test1","test2",...,"test1000")
>
> Thanks
> Xiaohua
>
> ______________________________________________
> R-help at 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
>



More information about the R-help mailing list