[R] Summing with NA
alain.guillet at uclouvain.be
Wed Mar 24 17:43:25 CET 2010
Do help(sum) to find more information about the option na.rm=T
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 elements which are not NA
> x2 <- x[x1]
>  -23
> 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 three vectors, e,z,k, and my
>> objective is to get an answer = -23.
>> I tried putting the na.omit but it did not work. Thanks.
>>  -12 -9
>>  -2 0
>>  NA NA
>>  NA
> R-help at r-project.org mailing list
> PLEASE do read the posting guide
> and provide commented, minimal, self-contained, reproducible code.
Statistician and Computer Scientist
SMCS - IMMAQ - Université catholique de Louvain
Voie du Roman Pays, 20
tel: +32 10 47 30 50
More information about the R-help