[R] how to save object created by assign()

Jinsong Zhao jszhao at yeah.net
Fri Nov 19 15:37:19 CET 2010

Hi there,

When I run the following code, I could get correct objects (with correct 

for(i in 1:6) { #-- Create objects  'r.1', 'r.2', ... 'r.6' --
       nam <- paste("r",i, sep=".")
       assign(nam, 1:i)
#     save(nam, file = paste(nam, "RData", sep = "."))

I hope to save the object 'r.1', 'r.2', ..., 'r.6' using the above 
commented line, however, I just got 'r.1.RData' with a object 'nam' in 
it, which had the value, e.g., 'r.6', not the value of 'r.6', i.e., 1:6.

Any suggestions? Thanks in advance.


More information about the R-help mailing list