[R] how to ignore NA when using cumsum?

2009-11-21 Thread Tracy Bowerman
I would like to cumulatively sum rows in a matrix, in which each row has 1 NA value. The usual na.rm=TRUE does not seem to work with the command cumsum. Is there another way to ignore the NAs or do I need to figure out a different way to do this? Here's an example matrix of title proportion:

Re: [R] how to ignore NA when using cumsum?

2009-11-21 Thread Ista Zahn
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

[R] how to ignore NA when using cumsum WHILE retaining NAs?

2009-11-21 Thread Tracy Bowerman
I would like to cumulatively sum rows in a matrix, in which each row has 1 NA value, which I do NOT want to treat as 0s. The NAs are placeholders where there is actually no data, which is not the same as a 0. The usual na.rm=TRUE does not seem to work with the command cumsum. Is there another

Re: [R] how to ignore NA when using cumsum WHILE retaining NAs?

2009-11-21 Thread William Dunlap
-Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tracy Bowerman Sent: Saturday, November 21, 2009 12:19 PM To: r-help Subject: [R] how to ignore NA when using cumsum WHILE retaining NAs? I would like to cumulatively sum rows

Re: [R] how to ignore NA when using cumsum?

2009-11-21 Thread Henrique Dallazuanna
Try this: apply(proportion, 1, function(x)cumsum(na.exclude(x))) On Sat, Nov 21, 2009 at 5:34 PM, Tracy Bowerman tracy.bower...@aggiemail.usu.edu wrote: I would like to cumulatively sum rows in a matrix, in which each row has 1 NA value.  The usual na.rm=TRUE does not seem to work with the