[R] Curious behaviour of lapply and lists of functions
Julio Sergio Santana
juliosergio at gmail.com
Thu Jan 16 01:58:48 CET 2014
Let's say I define a simple list of functions, as follows
lf <- list(
Then I can take any individual function from the list and
use it with any value, as it is shown:
this gives me the results I expected.
Then I create a function producer, that just generates a new function
from a given one:
Producer <- function(f) function(x) 1/f(x)
if I use it with the elements of the list of functions
again, the result is satisfactory.
However, if I try to produce a list of the new functions, this is
what I get
linv <- lapply(lf, Producer)
Of course this is not what I wanted.
Could anyone explain me this courious behaviour, and how to get
the two functions in linv?
More information about the R-help