[R] how to evaluate a dynamic variable?

Finny Kuruvilla kuruvill at fas.harvard.edu
Fri Apr 27 23:07:38 CEST 2007


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/



More information about the R-help mailing list