Reduce a list to a single value by iteratively applying a binary function
Source:R/utils.R
reduce.Rd
Inspired by reduce()
from the purrr
package
Arguments
- .x
A list or atomic vector.
- .f
A 2-argument function. The function will be passed the accumulated value as the first argument and the "next" value as the second argument.
- ...
Additional arguments passed on to
.f
.- .init
If supplied, will be used as the first value to start the accumulation, rather than using
x[[1]]
. This is useful if you want to ensure thatreduce
returns a correct value when.x
is empty. If missing, andx
is empty, will throw an error.
Author
Jonathon Love jon@thon.cc