Skip to content

how to ignore NA when using cumsum?

3 messages · Tracy Bowerman, Ista Zahn, Henrique Dallazuanna

#
Hi Tracy,
What do you want the program to do with the missing values? If you
want to treat them as zeros, you could use

cum.na <- function(x) {
x[which(is.na(x))] <- 0
return(cumsum(x))
}
cumsums <- apply(proportion, 1, cum.na)

-Ista

On Sat, Nov 21, 2009 at 2:34 PM, Tracy Bowerman
<tracy.bowerman at aggiemail.usu.edu> wrote:

  
    
#
Try this:

apply(proportion, 1, function(x)cumsum(na.exclude(x)))

On Sat, Nov 21, 2009 at 5:34 PM, Tracy Bowerman
<tracy.bowerman at aggiemail.usu.edu> wrote: