[R] produce variable on the fly
Erik Iverson
iverson at biostat.wisc.edu
Tue Aug 12 17:10:02 CEST 2008
?assign , or consider a named vector/list.
jimineep wrote:
> 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?
More information about the R-help
mailing list