Message-ID: <CAP01uRmHDrpBnfQBd5TrBOgHDgxC7K-EsvFvxd=pVmg4gjmTLQ@mail.gmail.com>
Date: 2012-02-09T00:52:16Z
From: Gabor Grothendieck
Subject: evaluate one variable in an expression with two variables
In-Reply-To: <1328734945084-4370877.post@n4.nabble.com>
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