[R] assignment to a symbol created by paste

Thomas Lumley tlumley at u.washington.edu
Thu Apr 13 23:56:01 CEST 2006


On Thu, 13 Apr 2006, Chad Reyhan Bhatti wrote:

> Hello,
>
> I am creating a number of objects that I wish to have a common name with
> an index such as x1, x2, x3, ... I would like to do everyting in a loop to
> make the code compact and minimize the probability of an error by typo.

see FAQ 7.21 (including the suggestion not to do this).

 	-thomas


> A test problem may look like
>
> for (j in 1:10){
> 	as.symbol(paste("x",j,sep="")) <- j;
> }
>
> which ideally would produce x1 = 1, ... x10 = 10.  However, this does not
> work.
>
>> as.symbol(paste("x",1,sep="")) <- 2
> Error: Target of assignment expands to non-language object
>>
>
> Any help?
>
> Thanks,
>
> Chad R. Bhatti
>
> ______________________________________________
> 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
>

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




More information about the R-help mailing list