[R] "Fold" in R?

Seung Jun jun at cc.gatech.edu
Sun Mar 27 19:18:54 CEST 2005


Fold in Mathematica (or reduce in Python) works as follows:

Fold[f, x, {a, b, c}] := f[f[f[x,a],b],c]

That is, f is a binary operator, x is the initial value, and the results 
are cascaded along the list.  I've found it useful for reducing lists 
when I only have a function that accepts two arguments (e.g., merge in R).

Is there any R equivalent?  I'm a newbie in R and having a hard time 
finding such one.  Thank you.

Seung




More information about the R-help mailing list