[R] access objects by name

jim holtman jholtman at gmail.com
Tue Jun 21 01:16:42 CEST 2011


for (thisOne in structs){
    print(get(thisOne)$colA)
}

you need to 'get' (retrieve) the object first.

On Mon, Jun 20, 2011 at 5:18 PM, Noah Silverman <noahsilverman at ucla.edu> wrote:
> Hi,
>
> I have several data structures (xts structures).  I then have a list of the names of those objects.
>
> I'd like to access the object by name.
>
> For example:
>
> foo1 <- as.xts(....)
> foo2 <- as.xts(...)
> foo3 <- as.xts(...)
>
> structs <- c("foo1", "foo2", "foo3")
>
> for (thisOne in structs){
>        print(thisOne$colA)
> }
>
> The above fails.  Clearly I'm missing a step translating the name to the object.
>
> Suggestions?
>
> Thanks
>
>
>
> --
> Noah Silverman
> UCLA Department of Statistics
> 8117 Math Sciences Building
> Los Angeles, CA 90095
> Cell:  (323) 899-9595
>
> ______________________________________________
> 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.
>



-- 
Jim Holtman
Data Munger Guru

What is the problem that you are trying to solve?



More information about the R-help mailing list