?Reduce maybe
HTH, baptiste 2009/9/16 OKB (not okblacke) <brenb...@brenbarn.net> > 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 Barnwell > "Do not follow where the path may lead. Go, instead, where there is > no path, and leave a trail." > --author unknown > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.