functional programming in R -
i have been reading functionals github. 1 suggestion in page use call_function
if 1 working list of functions. here code page:
call_fun <- function(f, ...) f(...) f <- list(sum, mean, median, sd) lapply(f, call_fun, x = runif(1e3))
the output posted as:
# [[1]] # [1] 498 # # [[2]] # [1] 0.498 # # [[3]] # [1] 0.49 # # [[4]] # [1] 0.29
however, not able replicate above results. got error:
error in fun(x[[4l]], ...) : not find function "f"
am missing here?
you have redefined function sd
:
sd = 2 call_fun <- function(f, ...) f(...) f <- list(sum, mean, median, sd) lapply(f, call_fun, x = runif(1e3)) #error in fun(x[[4l]], ...) : not find function "f"
restart session or rm(sd)
.
Comments
Post a Comment