[R] generate a series of fucntion
dmurdoch at pair.com
Mon Jul 21 22:24:55 CEST 2003
On Mon, 21 Jul 2003 15:54:24 -0400, ximing wu <xiwu at uoguelph.ca> wrote
>I want to generate a large amount of functions,
>say f=function(x,t) exp(-t-t*g_1(x)-t*g_2(1+x))
>where g_1(x) and g_2(x) are from a long list of moments, such as x, x^2,
>log(x), log(1+x) .. and so on.
>Any suggestions on how to do this efficiently?
I'd just have one function, with a definition like this:
f <- function(x, t, g1, g2) exp(-t-t*g1(x)-t*g2(1+x))
and pass different functions to it, e.g.
f(x, t, function(x) x, function(x) x^2)
If you really need separate functions, then still do what I suggest
above, but have your individual functions defined in terms of one,
f1 <- function(x,t) f(x, t, function(x) x, function(x) x^2)
More information about the R-help