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 putting the NA values at the end of each group. (I had to 
study it quite a bit to understand what was going on, and why! :-) )

I wish cumsum took a 'na.rm' argument, though. It would make stuff like 
this much easier.

-- 
Karl Ove Hufthammer

______________________________________________
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.

Reply via email to