[R] produce variable on the fly

Thomas Lumley tlumley at u.washington.edu
Tue Aug 12 21:45:41 CEST 2008


On Tue, 12 Aug 2008, Ben Bolker wrote:

> jimineep <jamesrperkins <at> hotmail.com> writes:
>
>>
>>
>> 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 is almost a candidate for a FAQ: see
>

It *is*  FAQ 7.21.

      -thomas


Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



More information about the R-help mailing list