Apply many functions to one vector

非 Y 不嫁゛ 提交于 2019-12-10 04:33:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!