I want to evaluate f with the mean=7 mean=7 f <- expression(-(x-mean)^2/2) then get a new expression: -(x-7)^2/2 How could I do it? Thanks. -- View this message in context: http://r.789695.n4.nabble.com/evaluate-one-variable-in-an-expression-with-two-variables-tp4370877p4370877.html Sent from the R help mailing list archive at Nabble.com.
Gabor Grothendieck
2012-Feb-09 00:52 UTC
[R] evaluate one variable in an expression with two variables
On Wed, Feb 8, 2012 at 4:02 PM, moli <nirdong at gmail.com> wrote:> I want to evaluate f with the mean=7 > > ?mean=7 > ?f <- ?expression(-(x-mean)^2/2) > then get a new expression: > > ?-(x-7)^2/2 > How could I do it? Thanks. >You can leave out the initial as.expression if you don't mind having a call object instead:> as.expression(do.call("substitute", list(f[[1]], list(mean = 7))))expression(-(x - 7)^2/2) -- Statistics & Software Consulting GKX Group, GKX Associates Inc. tel: 1-877-GKX-GROUP email: ggrothendieck at gmail.com