Re: [R] Generalized cumsum?

2009-09-16 Thread David Winsemius
On Sep 16, 2009, at 9:31 PM, OKB (not okblacke) wrote: David Winsemius wrote: cumapply <- function (FUN, X) { FUN <- match.fun(FUN) answer <- sapply(1:length(X), function(x) { FUN(X[1:x])} ) return(answer)} Cool, thanks. It's still interesting to me that there's no such thing

Re: [R] Generalized cumsum?

2009-09-16 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of OKB (not okblacke) > Sent: Wednesday, September 16, 2009 6:04 PM > To: r-h...@stat.math.ethz.ch > Subject: Re: [R] Generalized cumsum? > &g

Re: [R] Generalized cumsum?

2009-09-16 Thread OKB (not okblacke)
David Winsemius wrote: > cumapply <- function (FUN, X) > { FUN <- match.fun(FUN) > answer <- sapply(1:length(X), function(x) { FUN(X[1:x])} ) > return(answer)} Cool, thanks. It's still interesting to me that there's no such thing built-in. Best wishes, -- --OKB (not okbl

Re: [R] Generalized cumsum?

2009-09-16 Thread David Winsemius
On Sep 16, 2009, at 9:04 PM, OKB (not okblacke) wrote: David Winsemius wrote: No, Reduce reduces an entire vector to a single value by repeatedly combining adjacent elements. I'm looking to convert a vector to another vector where each element is some arbitrary aggregating function

Re: [R] Generalized cumsum?

2009-09-16 Thread OKB (not okblacke)
David Winsemius wrote: >> No, Reduce reduces an entire vector to a single value by >>repeatedly >> combining adjacent elements. I'm looking to convert a vector to >> another vector where each element is some arbitrary aggregating >> function applied to the first n elements of t

Re: [R] Generalized cumsum?

2009-09-16 Thread Ted Harding
On 16-Sep-09 21:17:10, David Winsemius wrote: > On Sep 16, 2009, at 5:09 PM, OKB (not okblacke) wrote: >> baptiste auguie wrote: >> >>> ?Reduce >>> >>> maybe >> >> No, Reduce reduces an entire vector to a single value by >> repeatedly >> combining adjacent elements. I'm looking to convert a

Re: [R] Generalized cumsum?

2009-09-16 Thread David Winsemius
On Sep 16, 2009, at 5:09 PM, OKB (not okblacke) wrote: baptiste auguie wrote: ?Reduce maybe No, Reduce reduces an entire vector to a single value by repeatedly combining adjacent elements. I'm looking to convert a vector to another vector where each element is some arbitrary aggre

Re: [R] Generalized cumsum?

2009-09-16 Thread David Winsemius
On Sep 16, 2009, at 5:00 PM, OKB (not okblacke) wrote: 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 lengt

Re: [R] Generalized cumsum?

2009-09-16 Thread OKB (not okblacke)
baptiste auguie wrote: > ?Reduce > > maybe No, Reduce reduces an entire vector to a single value by repeatedly combining adjacent elements. I'm looking to convert a vector to another vector where each element is some arbitrary aggregating function applied to the first n elements of t

Re: [R] Generalized cumsum?

2009-09-16 Thread baptiste auguie
?Reduce maybe HTH, baptiste 2009/9/16 OKB (not okblacke) >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

[R] Generalized cumsum?

2009-09-16 Thread OKB (not okblacke)
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