[R] Fixing Variables in a Function

Gabor Grothendieck ggrothendieck at gmail.com
Sat Oct 14 23:18:39 CEST 2006


Try this:

> f <- function(x, y, z) (x + y + z)^2
> integrate(f, 0, 1, x = 0, z = 0)  # integrate f setting x=z=0
0.3333333 with absolute error < 3.7e-15

On 10/14/06, Lorenzo Isella <lorenzo.isella at gmail.com> wrote:
> Dear All,
>
> I am working with functions of several variables, e.g. f(x,y,z).
> At some point, I would like to fix y and z and consider the resulting
> function of x only for numerical interation with the integrate
> routine.
> I know how to define a wrapper g<-function() {f(x,y,z)} , but I could
> not get a sort of wrapper for two variables.
> Any suggestions?
> Many thanks
>
> Lorenzo
>
> ______________________________________________
> 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
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list