Displaying 1 result from an estimated 1 matches for "cumapply".
2009 Sep 16
2
Generalized cumsum?
Is there anything like cumsum and cumprod but which allows you to
apply an arbitrary function instead of sum and product? In other words,
I want a function cumfunc(x, f) that returns a vector, so that for all n
up to the length of x
cumapply(x,f)[n] = f(x[1:n])
This would give cumsum and cumprod as special cases when f=sum or
f=prod.
I could write such a function, but I can't see a way to do it
without a loop, so I'm wondering if such a function exists that may be
speedier.
Thanks,
--
--OKB (not okblacke)
Brendan Ba...