[R] a simple list question

Rui Barradas ruipbarradas at sapo.pt
Wed Nov 7 12:44:07 CET 2012


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
>
>




More information about the R-help mailing list