Does R have something equivalent to reduce() in Python?

安稳与你 提交于 2019-11-30 12:58:44

问题


That is : "Apply function of two arguments cumulatively to the items of sequence, from left to right, so as to reduce the sequence to a single value. "


回答1:


Yes, it's called Reduce.

An example:

Reduce(paste, LETTERS[1:5])
[1] "A B C D E"

Reduce(sum, 1:5)
[1] 15

#List arguments work the same
Reduce(sum, list(1, 2, 3, 4, 5))
[1] 15

For more information about functional programming in R see the help file for ?funprog, an alias for ?Reduce




回答2:


Yes. See http://stat.ethz.ch/R-manual/R-patched/library/base/html/funprog.html



来源:https://stackoverflow.com/questions/7413819/does-r-have-something-equivalent-to-reduce-in-python

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