28

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

Assad Ebrahim
  • 6,234
  • 8
  • 42
  • 68
Derrick Zhang
  • 21,201
  • 18
  • 53
  • 73

2 Answers2

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
2

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

Dan D.
  • 73,243
  • 15
  • 104
  • 123