简体   繁体   中英

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

即:“将两个参数的函数累加到序列项中,从左到右,以便将序列减少为单个值。”

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM