[R] how to set the variable name in a loop
Pfaff, Bernhard
Bernhard.Pfaff at drkw.com
Mon Aug 4 16:27:24 CEST 2003
> Hello,
>
> I would like to have variables whose name are var1, var2, ...
> in a loop :
>
> for (i in 1:10)
> {
> var(i) <- i # where var(i) is var1, ....
> }
how about:
for (i in 1:10){
eval(parse(text=paste("var", i, "<-", i, sep="")))
}
HTH,
Bernhard
>
> Thanks in advance
>
> Philippe
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
>
----------------------------------------------------------------------
If you have received this e-mail in error or wish to read our e-mail
disclaimer statement and monitoring policy, please refer to
http://www.drkw.com/disc/email/ or contact the sender.
More information about the R-help
mailing list