Hi R-fellows,
can anyone explain this weird feature? I am trying to create a list of
functions with apply, and it appears that there is something strange going
on when the function evaluates the argument a. When I duplicate a into a
local variable b, the result changes !?!
Any pointers? Thank in advance. Cheers,
Uffe
# Create a function which returns a function
f1 <- function(a) {return(function(x) a*x)}
# Create a list of functions, parameterised by 1:4
apply(as.array(1:4),1,f1)[[2]](1)
f2 <- function(a) {b <- a ;return(function(x) b*x)}
apply(as.array(1:4),1,f2)[[2]](1)