[R] piecing together statements (macro?)

Gabor Grothendieck ggrothendieck at gmail.com
Sat Mar 10 15:30:14 CET 2007


Read the FAQ 7.21:

http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html#How-can-I-turn-a-string-into-a-variable_003f

Note that it points out that you don't really want to do this anyways.

On 3/9/07, toby909 at gmail.com <toby909 at gmail.com> wrote:
> Hi All
>
> I am pretty new to R but saw stata and sas's macro facilities and am looking for
> how such things work in R.
>
> I am trying to piece together a series of statements:
>
>
> n = 5   #want to have it dynamic with respect to n
> for (j in 1:n) {
> eval(paste("x", j, "=x[", j, "]", sep=""))
> }
>
> I want the created statements 'x1=x[1]' immediately executed and tried to do
> that with eval() but that did not work.
>
> Any hints greatly appreciates.
>
> Thanks Toby
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list