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
On Thu, 29 Jun 2006, Xiaohua Dai 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")I don't know why you would want to use a for loop: stringlist<-as.list(paste("test",1:1000,sep="")) testlist<-lapply(stringlist, as.name) -thomas
Gabor Grothendieck
2006-Jun-29 22:34 UTC
[R] How to use a for loop to generate two sequences
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 >