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. "
Asked
Active
Viewed 8,531 times
2 Answers
61
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

Richie Cotton
- 118,240
- 47
- 247
- 360

Andrie
- 176,377
- 47
- 447
- 496
-
20+1 for making me spit coffee out my nose after reading the first line. – John Sep 14 '11 at 10:25
-
1@John All in a day's work... Top of the morning, to you, too! – Andrie Sep 14 '11 at 10:29
-
2`Reduce("+",1:5)` is slightly clearer that its working on a function of 2 arguments. – James Sep 14 '11 at 13:50
-
8just a note on `"+"` vs `sum`:`Reduce(sum, list(c(1,2), c(3,4))) = 10`, while `Reduce("+", list(c(1,2), c(3,4))) = c(4,6)` – Colbert Sesanker Mar 10 '13 at 20:32
-
Why is it upper Case? – Valentas May 03 '16 at 09:56