[R] "Fold" in R?

From: Seung Jun <jun_at_cc.gatech.edu>
Date: Mon 28 Mar 2005 - 03:18:54 EST

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.


R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Mon Mar 28 03:24:42 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:56 EST