[R] Odp: create variables with indexes

Petr PIKAL petr.pikal at precheza.cz
Wed Jul 14 09:34:56 CEST 2010


Hi

r-help-bounces at r-project.org napsal dne 14.07.2010 00:44:02:

> Hi, there:
> 
> Suppose I want create variables with indexes in their names, e.g., 
X_1_1, 
> X_1_2, X_1_3, ..., X_1_10,  X_2_1, X_2_2, X_2_3, .. X_2_10,..., X_10_1, 
> X_10_2, ... X_10_10. It looks like I need to use 2 indexes I and J so I 
is 
> looped from 1 to 10, and J is looped from 1 to 10. But I don't know how 
to 
> automatically produce X with these combination of indexes. Should I use 
paste 
> function? Can someone help?

I would make a character vector, which I could use in further naming 
purpose.
paste(paste("x", rep(1:10, 10), sep="_"), rep(1:10, each=10), sep="_")

But why not to use lists?

Petr

> 
> Thanks.
> 
> Yulei
> 
> 
>    [[alternative HTML version deleted]]
> 
> ______________________________________________
> R-help at 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.



More information about the R-help mailing list