do.call
Description
do.call constructs and executes a function call from a name or a function and a list of arguments to be passed to it.
Usage
do.call(what, args, quote = FALSE, envir = parent.frame())
Arguments
what: either a function or a non-empty character string naming the function to be called.
args: a list of arguments to the function call. The names attribute of args gives the argument names.
quote: a logical value indicating whether to quote the arguments.
envir: an environment within which to evaluate the call. This will be most useful if what is a character string and the arguments are symbols or quoted expressions.
example
df_1 <- data.frame(x = c(1,2,3,4,5), y = c(4,7,7,9,10), z = c(19,11,24,14,57))
df_2 <- data.frame(x = c(1,2,3,4,5), y = c(42,72,72,92,34), z = c(191,111,241,141,45))
df_3 <- data.frame(x = c(1,2,3,4,5), y = c(42,721,721,921,112), z = c(1911,1111,2411,1411,5711))
list = list(df_1,df_2,df_3)
merge1 <- function(x,y,z){
merge(x,y,z, by='x',all=TRUE)
}
do.call(merge1, list)
Reduce(function(x,y) merge(x = x, y = y, by = "x",all=TRUE), list)
Reduce(merge1, list)
网友评论