问题
I am looking for an option to apply many functions to one vector. I think it is kind on an inverse apply function where one function is applied to many vectors (or columns).
Is there a way of specifing two or more functions (like mean and max) and apply this on a vector?
回答1:
Similar to @CathG's comment, but without get:
v <- rnorm(10)
funs <- list(mean, median, sd)
sapply(funs, function(fun, x) fun(x), x = v)
Or with do.call:
sapply(funs, do.call, args = list(v))
来源:https://stackoverflow.com/questions/30979206/apply-many-functions-to-one-vector