And the ls()[grep("^x\\.[[:digit:]]+$", ls())] can be simplified to grep("^x\\.[[:digit:]]+$", ls(), value=TRUE)
Bill Dunlap Spotfire, TIBCO Software wdunlap tibco.com > -----Original Message----- > From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf > Of David L Carlson > Sent: Wednesday, November 07, 2012 8:25 AM > To: 'Rui Barradas'; 'Erin Hodgess' > Cc: 'R help' > Subject: Re: [R] a simple list question > > Combining your, Rolf, and Michael's suggestions makes it possible > to eliminate the lappy(): > > mget(ls()[grep("^x\\.[[:digit:]]+$", ls())], .GlobalEnv) > > ---------------------------------------------- > David L Carlson > Associate Professor of Anthropology > Texas A&M University > College Station, TX 77843-4352 > > > -----Original Message----- > > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > > project.org] On Behalf Of Rui Barradas > > Sent: Wednesday, November 07, 2012 9:49 AM > > To: Erin Hodgess > > Cc: R help > > Subject: Re: [R] a simple list question > > > > Hello, > > > > My solution is too complicated, the assign() is not needed. > > > > > > lapply( ls()[grep("^x\\.[[:digit:]]+$", ls())], get) > > > > > > Hope this helps, > > > > Rui Barradas > > Em 07-11-2012 11:44, Rui Barradas escreveu: > > > Hello, > > > > > > Try the following. > > > > > > x.1 <- 1:3 > > > y.1 <- 1:4 > > > x.2 <- 5:10 > > > > > > > > > vecs <- ls()[grep("^x\\.[[:digit:]]+$", ls())] > > > lapply(vecs, function(.x) assign(.x, get(.x))) > > > > > > > > > Then you can use vecs to attribute names() to the result. > > > > > > Hope this helps, > > > > > > Rui Barradas > > > > > > Em 07-11-2012 05:35, Erin Hodgess escreveu: > > >> Dear R People > > >> > > >> I have a simple list question, please: > > >> > > >> I have vectors x.1, x.2,...x.n (each of different lengths) and I > > would > > >> like to combine them into a list. > > >> > > >> However, I'm sure that there is a better way to do this than to type > > >> in x <- list(x.1,x.2,x.3,...) > > >> > > >> > > >> Is there a better way to do this, please? I was thinking about > > >> possibly using grep? > > >> > > >> Thanks, > > >> Sincerely, > > >> Erin > > >> > > >> > > > > > > ______________________________________________ > > > R-help@r-project.org mailing list > > > https://stat.ethz.ch/mailman/listinfo/r-help > > > PLEASE do read the posting guide > > > http://www.R-project.org/posting-guide.html > > > and provide commented, minimal, self-contained, reproducible code. > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting- > > guide.html > > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.