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
I'm not sure if I'm understanding what you're asking for but this may be it:> DV="b" > assign(DV,1:4) > DV[1] "b"> b[1] 1 2 3 4 On Fri, 27 Apr 2007, Bobby Prill wrote:> 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. >***************************************************************** Finny Kuruvilla, MD, PhD Harvard Medical School Fellowship Program in Transfusion Medicine Broad Institute of MIT and Harvard Homepage: http://www.people.fas.harvard.edu/~kuruvill/home/
What are you trying to do with that? Most times when someone asks this question, they are trying to accomplish something that can be done better a different way, so if you tell us what you are trying to accomplish, we can suggest better approaches. The short answer to your question is ?get. -- Gregory (Greg) L. Snow Ph.D. Statistical Data Center Intermountain Healthcare greg.snow at intermountainmail.org (801) 408-8111> -----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 2: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. >
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).
Does get(DV) do what you want? -Don At 4:35 PM -0400 4/27/07, Bobby Prill wrote:>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.-- -------------------------------------- Don MacQueen Environmental Protection Department Lawrence Livermore National Laboratory Livermore, CA, USA