views:

108

answers:

1

Hi,

I would like to know if there is an implementation of the foldLeft function (and foldRight?) in R.

The language is supposed to be "rather" functional oriented and hence I think there should be something like this, but I could not find it in the documentation.

To me, foldLeft function applies on a list and has the following signature:

foldLeft[B](z : B)(f : (B, A) => B) : B

It is supposed to return the following result:

f(... (f(f(z, a0), a1) ...), an) if the list is [a0, a1, ..., an].

(I use the definition of the Scala List API)

Does anybody know if such a function exists in R?

+5  A: 

?Reduce. Usage Reduce(f, x, init, right = FALSE, accumulate = FALSE)

ahala
arf. I knew I had seen it somewhere!Do you know if there is a package dedicated to list handling with optimal functions? or are they all already implemented in the base package and I did not find them?
JSmaga