[R] Problem accessing .Rdata objects in a loop

francy francy.casalino at gmail.com
Tue Apr 17 17:38:22 CEST 2012


Hi,

I am trying to access many .Rdata objects and do some operations with them
using a loop. I can load the files but can't access them. The files' names
are stored in a character vector called "names".  After loading the objects,
I can view each one using ls() and see that two objects are present for
each. I am trying to access the one with the name which is the same as the
name of the .Rdata. I can access individual .Rdata object using backticks
around its name like this:

names<- c("df1", "df2", "df3")
load(paste(path, "/", df1, ".RData", sep="")
df<- `df1`

But when I try using the variable name in a loop it does not work:

for (n in names) {
print(names)
load(paste(path,  "/", names, ".RData", sep=""))
df<- `n`
###do some other operations with each object
}

Could you please help me understand what I can do to view these objects?

Thank you.

--
View this message in context: http://r.789695.n4.nabble.com/Problem-accessing-Rdata-objects-in-a-loop-tp4565154p4565154.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list