Re: evaluate one variable in an expression with two variables

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Re: evaluate one variable in an expression with two variables

Gabor Grothendieck
On Wed, Feb 8, 2012 at 4:02 PM, moli <[hidden email]> 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

______________________________________________
[hidden email] 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.