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
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
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
Hello,
I am
On Wed, 11 Nov 2009 08:53:50 -0800 William Dunlap wdun...@tibco.com
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
On Wed, 11 Nov 2009 18:11:51 +0100 Karl Ove Hufthammer k...@huftis.org
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
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
-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:
Perhaps
ave(x, rev(cumsum(rev(is.na
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
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
using
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 which
10 matches
Mail list logo