[R] assign

Roger D. Peng rpeng at jhsph.edu
Wed Jan 7 18:53:10 CET 2004


Use assign().

varnames <- paste("x", 1:10, sep = ".")
for(j in 1:10) {
	assign(varnames[j], rnorm(10))
}

-roger

Perez Martin, Agustin wrote:
> DeaR useRs:
> 
> I would like to assign a values in an object using a loop 'for'.
> This is a reduce example of my problem, my real problem is a few
> complicated:
> 
> for (j in 1:10) {
> 	x.j<-rnorm(100)
> }
> 
> I want to create 10 objects as "x.1, x.2, ... , x.9, x.10" with values in
> it.
> I used the "assign" function but nothing happens.
> Thank you very much
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list