[R] evaluating expressions with sub expressions
Jennifer Young
Jennifer.Young at math.mcmaster.ca
Fri Jan 29 17:51:31 CET 2010
Hallo
I'm having trouble figuring out how to evaluate an expression when one of
the variables in the expression is defined separately as a sub expression.
Here's a simplified example
mat <- expression(0, f1*s1*g1) # vector of formulae
g1 <- expression(1/Tm) # expansion of the definition of g1
vals <- data.frame(f1=1, s1=.5, Tm=2) # one set of possible values for
variables
before adding this sub expression I was using the following to evaluate "mat"
sapply(mat, eval, vals)
Obviously I could manually substitute in 1/Tm for each g1 in the
definition of "mat", but the actual expression vector is much longer, and
the sub expression more complicated. Also, the subexpression is often
adjusted for different scenarios. Is there a simple way of changing this
or redefining "mat" so that I can define "g1" like a macro to be used in
the expression vector.
Thanks!
Jennifer
More information about the R-help
mailing list