[R] how to evaluate a dynamic variable?

Bobby Prill rprill at jhu.edu
Fri Apr 27 23:13:01 CEST 2007


Mark,

You're right.  Thank you.  Look, it works:

 > a = c(1,2,3)
 > a
[1] 1 2 3

 > b = "a"
 > b
[1] "a"

 > get(b)
[1] 1 2 3


On Apr 27, 2007, at 5:05 PM, Leeds, Mark (IED) wrote:

> check out get using ?get. I'm not an expert but that might help or
> work.
>
>
>
> -----Original Message-----
> From: r-help-bounces at stat.math.ethz.ch
> [mailto:r-help-bounces at stat.math.ethz.ch] On Behalf Of Bobby Prill
> Sent: Friday, April 27, 2007 4:35 PM
> To: r-help at stat.math.ethz.ch
> Subject: [R] how to evaluate a dynamic variable?
>
> Please help me evaluate a "dynamic variable" as show in the code  
> snippet
> below.
>
> # regular variable
> a = c(1,2,3,4)
>
> # dynamic variable set at runtime
> DV = "a"
>
> eval(DV)
> --> a
>
> eval(eval(DV))
> --> a
>
> # what I want
> something_goes_here(DV)
> -->  1,2,3,4
>
> Can someone teach me how to do this?  Thanks very much.
>
> - Bobby
>
> ______________________________________________
> R-help at stat.math.ethz.ch 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.
> --------------------------------------------------------
>
> This is not an offer (or solicitation of an offer) to buy/sell the  
> securities/instruments mentioned or an official confirmation.   
> Morgan Stanley may deal as principal in or own or act as market  
> maker for securities/instruments mentioned or may advise the  
> issuers.  This is not research and is not from MS Research but it  
> may refer to a research analyst/research report.  Unless indicated,  
> these views are the author's and may differ from those of Morgan  
> Stanley research or others in the Firm.  We do not represent this  
> is accurate or complete and we may not update this.  Past  
> performance is not indicative of future returns.  For additional  
> information, research reports and important disclosures, contact me  
> or see https://secure.ms.com/servlet/cls.  You should not use e- 
> mail to request, authorize or effect the purchase or sale of any  
> security or instrument, to send transfer instructions, or to effect  
> any other transactions.  We cannot guarantee that any such requests  
> received via e-mail will be processed in a timely manner.  This  
> communication is solely for the addressee(s) and may contain  
> confidential information.  We do not waive confidentiality by  
> mistransmission.  Contact me if you do not wish to receive these  
> communications.  In the UK, this communication is directed in the  
> UK to those persons who are market counterparties or intermediate  
> customers (as defined in the UK Financial Services Authority's rules).



More information about the R-help mailing list