在Python中,R是否具有与reduce()等价的内容?

时间:2022-03-30 22:01:19

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. "

即:“将两个参数的函数从左到右累积地应用到序列项中,从而将序列减少到单个值。””

2 个解决方案

#1


60  

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

有关R中的函数编程的更多信息,请参见“?funprog”的帮助文件,“?Reduce”的别名

#2


2  

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

是的。参见http://stat.ethz.ch/R-manual/R-patched/library/base/html/funprog.html

#1


60  

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

有关R中的函数编程的更多信息,请参见“?funprog”的帮助文件,“?Reduce”的别名

#2


2  

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

是的。参见http://stat.ethz.ch/R-manual/R-patched/library/base/html/funprog.html