[R] produce variable on the fly

jimineep jamesrperkins at hotmail.com
Tue Aug 12 14:54:29 CEST 2008


Hi guys,

I want to create variable on the fly: for example

for (i in 1:10) {
    cat(paste("VAR",i,sep=""))
}
Will print VAR1, VAR2 etc up to VAR10. However I want to make these into
variables, and then give them a value, for example:

vect = c(10:20)

for (i in 1:10) {
    cat(paste("VAR",i,sep="")) = vect[i]
}

THis doesnt work but I hope it demonstrates what I'm trying to do: I'm
trying to produce 10 variables, from VAR1 to VAR10, which have the numbers
11...20 respectively, so I would end up with 

VAR1 = 11
VAR2 = 12
...
VAR10 = 20

Hope this makes sense!! Does anyone have any ideas?
-- 
View this message in context: http://www.nabble.com/produce-variable-on-the-fly-tp18943749p18943749.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list