Skip to content
Prev 75095 / 398502 Next

problems with function-formating, please help

Joerg Burmester wrote:
You should almost never write text and reparse it -- it almost always 
indicates  a poor solution to whatever problem you're trying to solve.

I can't tell from your message what you want your function to do, but if 
you want a function that takes args x1, x2, x3 and returns the value 
1.60638946783994e-05 + 384.649339378693 * x1 - 168.920548209815 * x2 - 
693.51261768584 * x3 + 479.305764753298 * x1 * x3, where those 
coefficients come from some other calculation, just do it like this:

makefn <- function(coeffs) {
   function(x1, x2, x3) coeffs[1] +
                        coeffs[2]*x1 +
                        coeffs[3]*x2 +
                        coeffs[4]*x1*x3
}

Then use it like this:

f <- makefn(c(-1.606, 384.64, etc.))

and f is the function you want.

Duncan Murdoch