Efficient Fold, Reduce, Accumulate, Combine of a Vector
Efficient Fold, Reduce, Accumulate, Combine of a Vector
fold(x, f, left = TRUE, unname = TRUE, threshold = 1000L)
x |
A vector. |
f |
A binary function, i.e. a function take takes two arguments. |
left |
If |
unname |
If |
threshold |
An integer (>= 2) specifying the length where the
recursive divide-and-conquer call will stop and incremental building of
the partial value is performed. Using |
In order for recursive folding to give the same results as non-recursive
folding, binary function f
must be associative with itself, i.e.
f(f(x[[1]], x[[2]]), x[[3]])
equals
f(x[[1]], f(x[[2]]), x[[3]])
.
This function is a more efficient (memory and speed) of
Reduce(f, x, right = !left, accumulate = FALSE)
,
especially when x
is long.
A vector.
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.