[R] Creating object referant from argument name

jim holtman jholtman at gmail.com
Mon Oct 12 22:19:55 CEST 2009


try this:  (?get)

j<- get(paste("list",substring(input,3,3),sep=""))

On Mon, Oct 12, 2009 at 4:14 PM, Maxwell Reback <mreback at gmail.com> wrote:
> Hi all. I'd like to define an object within a function based on an
> argument to that function.
> Specifically, I've got:
>
> do.something<-function(input){
> id<-substring(input,3,3)
> j<-list1
> if(id==2)j<-list2
> if(id==3)j<-list3
> if(id==4)j<-list4
> ...}
>
> Instead of all these if() arguments, I was hoping to use something like:
> j<-paste("list",substring(input,3,3),sep="")
> but this just assigns j the value of "listx" of _character_ mode,
> instead of the actual object 'listx'.
> Is there any way to get around this?
> Thanks.
>
> ______________________________________________
> 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
Cincinnati, OH
+1 513 646 9390

What is the problem that you are trying to solve?




More information about the R-help mailing list