[英]Does R have something equivalent to reduce() in Python?
即:“将两个参数的函数累加到序列项中,从左到右,以便将序列减少为单个值。”
Yes, it's called Reduce
. 是的,它叫做
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
有关R中函数编程的更多信息,请参阅帮助文件
?funprog
, ?Reduce
的别名
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.