I\'m learning R recently and confused by two function: lapply
and do.call
. It seems that they\'re just similar to map
function in Lisp.
lapply
is similar to map
, do.call
is not. lapply
applies a function to all elements of a list, do.call
calls a function where all the function arguments are in a list. So for a n
element list, lapply
has n
function calls, and do.call
has just one function call. So do.call
is quite different from lapply
. Hope this clarifies your issue.
A code example:
do.call(sum, list(c(1, 2, 4, 1, 2), na.rm = TRUE))
and:
lapply(c(1, 2, 4, 1, 2), function(x) x + 1)