Skip to content
Prev 198782 / 398506 Next

save an object by dynamicly created name

On Nov 1, 2009, at 10:16 PM, Henrik Bengtsson wrote:

            
That would result in each of the ten files containing an object with  
the same  name == "m". (Also on my system R data files have type  
Rdta.) So I thought what was requested might have been a slight mod:

path <- "~/";
dir.create(path);

for (i in 1:10) {
  assign( paste("m", i, sep=""),  i:5)
  filename <- sprintf("m%02d.Rdta", i)
  pathname <- file.path(path, filename)
  obj =get(paste("m", i, sep=""))
  save(obj, file=pathname)
}