thank u very much Wiliam Dunlap,
your function is very helpful, i been trying to find the right algo,,,and i
saw yours, it works perfectly.
i even checked with system.time function, and it's clear the cum.reset is
the best.
> system.time(ave(J, rev(cumsum(rev(is.na(J, FUN=cumsum))
utilisateur
On Nov 11, 2009, at 4:45 PM, Carl Witthoft wrote:
> By Bill Dunlap:
quote:
> x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10)
> rev(cumsum(rev(is.na(x
[1] 1 1 1 1 0 0 0 0 0 0
A more natural way to do this is
> cumsum(is.na(c(NA,x[-length(x)])))
[1] 1 1 1 1 2 2 2 2 2 2
endquote
Both of whi
quote:
> x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10)
> rev(cumsum(rev(is.na(x
[1] 1 1 1 1 0 0 0 0 0 0
A more natural way to do this is
> cumsum(is.na(c(NA,x[-length(x)])))
[1] 1 1 1 1 2 2 2 2 2 2
endquote
Both of which suggest the original problem could also be dealt with by
usin
William Dunlap wrote:
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
-Original Message-
From: r-help-boun...@r-project.org
[mailto:r-help-boun...@r-project.org] On Behalf Of smu
Sent: Wednesday, November 11, 2009 7:58 AM
To: r-help@r-project.org
Subject: [R] partial cumsum
> -Original Message-
> From: smu [mailto:m...@z107.de]
> Sent: Wednesday, November 11, 2009 9:26 AM
> To: William Dunlap
> Cc: r-help@r-project.org
> Subject: Re: [R] partial cumsum
>
> On Wed, Nov 11, 2009 at 08:53:50AM -0800, William Dunlap wrote:
> >
&
On Wed, Nov 11, 2009 at 08:53:50AM -0800, William Dunlap wrote:
>
> Perhaps
>> ave(x, rev(cumsum(rev(is.na(x, FUN=cumsum)
> [1] 1 3 6 NA 5 11 18 26 35 45
>
it takes some time to understand how it works, but it's perfect.
thank you,
stefan
__
On Wed, 11 Nov 2009 18:11:51 +0100 Karl Ove Hufthammer
wrote:
> I wish cumsum took a 'na.rm' argument, though. It would make stuff like
> this much easier.
Or, more specifically, a 'na.value', which could perhaps default to
'NA' to get the current behaviour, but which one could set 0 for
'cum
On Wed, 11 Nov 2009 08:53:50 -0800 William Dunlap
wrote:
> > x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10)
> >
> > should become this:
> >
> > 1 3 6 NA 5 11 18 26 35 45
>
> Perhaps
>> ave(x, rev(cumsum(rev(is.na(x, FUN=cumsum)
> [1] 1 3 6 NA 5 11 18 26 35 45
Clever way of puttin
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -Original Message-
> From: r-help-boun...@r-project.org
> [mailto:r-help-boun...@r-project.org] On Behalf Of smu
> Sent: Wednesday, November 11, 2009 7:58 AM
> To: r-help@r-project.org
> Subject: [R] partial
Hello,
I am searching for a function to calculate "partial" cumsums.
For example it should calculate the cumulative sums until a NA appears,
and restart the cumsum calculation after the NA.
this:
x <- c(1, 2, 3, NA, 5, 6, 7, 8, 9, 10)
should become this:
1 3 6 NA 5 11 18 26 35 45
any i
10 matches
Mail list logo