Skip to content
Prev 317720 / 398506 Next

Handling NA values

Hi,
Try this:
ifelse(rowSums(is.na(Mat))==ncol(Mat),NA,rowSums(Mat,na.rm=TRUE))
#[1]? 0? 3 NA
A.K.



----- Original Message -----
From: Christofer Bogaso <bogaso.christofer at gmail.com>
To: Marc Schwartz <marc_schwartz at me.com>
Cc: r-help <r-help at r-project.org>
Sent: Saturday, February 16, 2013 1:22 PM
Subject: Re: [R] Handling NA values

Thanks Marc for your reply.

However this leads to my problem of handling rowSums() function (hence
colSums()). Let take following matrix:
? ?  [,1] [,2] [,3]
[1,]? ? 1?  -1?  NA
[2,]? ? 1? ? 1? ? 1
[3,]?  NA?  NA?  NA
[1] 0 3 0

I want to have some way to distinguish the 1st '0' and the 3rd '0'. I
want to see NA directly for the 3rd. Any possibility how to do that
through the rowSum() function?

Thanks and regards,
On Sat, Feb 16, 2013 at 11:52 PM, Marc Schwartz <marc_schwartz at me.com> wrote:
______________________________________________
R-help at 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.