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

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 sameReduce(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