[R] Problem accessing .Rdata objects in a loop
Bert Gunter
gunter.berton at gene.com
Tue Apr 17 18:07:36 CEST 2012
Try reading ?load again.
It takes a single filename only.
Also 'n' is a character, not a symbol for a variable. I think you
need to do some reading on basic programming. Try An Introduction to R
(part of the distro) to get you going.
-- Bert
On Tue, Apr 17, 2012 at 8:38 AM, francy <francy.casalino at gmail.com> wrote:
> 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.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Bert Gunter
Genentech Nonclinical Biostatistics
Internal Contact Info:
Phone: 467-7374
Website:
http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm
More information about the R-help
mailing list