[R] generate a series of fucntion
Duncan Murdoch
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
:
>Hi there,
>
>I want to generate a large amount of functions,
>
>say f=function(x,t) exp(-t[1]-t[2]*g_1(x)-t[3]*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[1]-t[2]*g1(x)-t[3]*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,
e.g.
f1 <- function(x,t) f(x, t, function(x) x, function(x) x^2)
Duncan Murdoch
More information about the R-help
mailing list