[R] Curious behaviour of lapply and lists of functions

Julio Sergio Santana juliosergio at gmail.com
Thu Jan 16 02:20:25 CET 2014

Julio Sergio Santana <juliosergio <at> gmail.com> writes:

> ...
>     Producer <- function(f) function(x) 1/f(x)

Counsulting a previous post, I got to the solution, I just need to rewrite 
the function Producer forcing it to eavaluate its argument, as follows

    Producer <- function(f) {f ;function(x) 1/f(x)}


    linv <- lapply(lf, Producer)

   [1] 0.125

   [1] 0.1666667

Which is the desired result.

Thanks everybody for reading.


More information about the R-help mailing list