[R] assignment to a symbol created by paste

Chad Reyhan Bhatti bhatticr at stat.rice.edu
Thu Apr 13 22:04:44 CEST 2006


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.
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

> as.symbol(paste("x",1,sep="")) <- 2
Error: Target of assignment expands to non-language object

Any help?


Chad R. Bhatti

More information about the R-help mailing list