Re: [R] Summing with NA

2010-03-24 Thread Alain Guillet
Hi, Do help(sum) to find more information about the option na.rm=T > sum(c(z,e,k),na.rm=T) [1] -23 Alain On 24-Mar-10 17:21, Muhammad Rahiz wrote: Slightly longer method, but works as well. z <- c(-12,-9) e <- c(-2,0) k <- c(NA,NA) x <- c(z,e,k) x1 <- which(x!="NA",arr.ind=TRUE) # get el

Re: [R] Summing with NA

2010-03-24 Thread William Dunlap
> -Original Message- > From: r-help-boun...@r-project.org > [mailto:r-help-boun...@r-project.org] On Behalf Of Muhammad Rahiz > Sent: Wednesday, March 24, 2010 9:21 AM > To: tj > Cc: r-help@r-project.org > Subject: Re: [R] Summing with NA > > Slightly longe

Re: [R] Summing with NA

2010-03-24 Thread Muhammad Rahiz
Slightly longer method, but works as well. z <- c(-12,-9) e <- c(-2,0) k <- c(NA,NA) x <- c(z,e,k) x1 <- which(x!="NA",arr.ind=TRUE) # get elements which are not NA x2 <- x[x1] sum(x2) [1] -23 -- Muhammad tj wrote: Hi all, May I request for your help if you have time and if you have an i

Re: [R] Summing with NA

2010-03-22 Thread David Winsemius
On Mar 22, 2010, at 9:51 PM, tj wrote: Hi all, May I request for your help if you have time and if you have an idea on how to do this. I want to add three vectors... And my goal is to obtain the sum of the vectors, ignoring the vector of "na"... Here is what i did in R.. I'm adding the

Re: [R] Summing with NA

2010-03-22 Thread stephen sefick
k <- c(NA, NA) z <- c(-12, -9) e <- c(-2,0) sum(na.omit(c(z, e, k))) Will this do the trick? Why are you summing in a sum() sum(k+z+e) On Mon, Mar 22, 2010 at 8:51 PM, tj wrote: > > Hi all, > May I request for your help if you have time and if you have an idea on how > to do this.  I want to a

[R] Summing with NA

2010-03-22 Thread tj
Hi all, May I request for your help if you have time and if you have an idea on how to do this. I want to add three vectors... And my goal is to obtain the sum of the vectors, ignoring the vector of "na"... Here is what i did in R.. I'm adding the three vectors, e,z,k, and my objective is to ge