[R] Get variable data Reading from the list

R. Michael Weylandt michael.weylandt at gmail.com
Wed Aug 29 06:18:23 CEST 2012


On Tue, Aug 28, 2012 at 8:19 AM, Rantony <antony.akkara at ge.com> wrote:
> Here i have a variable
>
> MyVar <- data.frame(read.csv("D:\\Doc.csv"))

read.csv() returns a data.frame so the outer call to data.frame() is
superfluous.

>
> And now i am storing this variable name into  a list.
>
> MyList <- list()
> MyList [length(MyList )+1]<- "MyVar"
>
> Now what is the requirement is,
>  i need to call the variable name "MyVar" from the list "MyList " and get
> the data.
> ------------------------------------------------------------------------------------------------------------------------
> i tried with get(MyList [1]). - it not work-out.

Close:

You want

get(MyList)[1]

which gets the variable "MyList" -- else you are telling R to look for
something called "MyList[1]" which is a rare, but not actually
impossible object name.

As before, you really don't want to be using get() and assign() for
this sort of stuff though.

Please do try to do things the idiomatic way: it'll be easier in the
long run : I promise.

Cheers,
Michael
>
> Can you please help me ?
>
> - Thanks in advance
> Antony.
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Get-variable-data-Reading-from-the-list-tp4641559.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.




More information about the R-help mailing list