[R] evaluate expression on several dataframe columns

Uwe Ligges ligges at statistik.uni-dortmund.de
Mon Dec 20 12:17:53 CET 2004


R user wrote:

> Hi R-users,
> 
> I have a collection of dataframes and know how to build
> a string that refers to it, in this example, name_infra_alg_inc.
> Then, I have a character string yval, which the user can select
> from a drop down list. It contains the column names of the
> dataframes.
> 
> assign(paste(name_infra_alg_inc, "ci", sep="."),
>   ci(get(name_infra_alg_inc)[[yval]], confidence=0.95))
> 
> My problem is that I sometimes want to combine columns.
> For example, if there are columns A, B and C.
> Would it be possible that yval has the value "A+B*C" and
> then call some sort of evaluate function?
> Maybe I could attach the dataframe and then call some function,
> I don't know how to figure this out, so hopefully someone can help me.
> 
> Thanks in advance


Anonymous R user,

I really don't know why are you going to do so, but you can do:

A <- 1
B <- 2
C <- 3
x <- expression(A+B*C)
eval(x)

Uwe Ligges


> ______________________________________________
> 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




More information about the R-help mailing list