On Nov 7, 2012, at 6:07 AM, Rolf Turner <rolf.tur...@xtra.co.nz> wrote:
> On 07/11/12 18:35, Erin Hodgess wrote: >> 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? > > If I understand your question correctly --- always a dubious assumption --- > you could do: > > n <- <however many vectors you have> > xlist <- lapply(1:n,function(n){get(paste("x",n,sep="."))}) > > Does that accomplish your goal? > > cheers, > > Rolf > Perhaps an hair shorter with mget() Michael > ______________________________________________ > 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.