[R] a problem with is.na

Martyn Byng Martyn.Byng at nag.co.uk
Wed Jan 26 13:41:50 CET 2011


Hi,

This isn't an issue with is.na, you get the same if you use

aa = c(1,1,0,1,1,1,1,1,1)
bb = abs(aa - 1)
xtabs(aa~x1+x2)
xtabs(bb~x1+x2)

it is because you do not have any data in (1,1), i.e. there is no case where x1 = 1 and x2 = 1 so xtabs is putting a zero in that cell

Hope this helps

Martyn

-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of René Holst
Sent: 26 January 2011 11:05
To: r-help at r-project.org
Subject: [R] a problem with is.na

Hello,

I have observed the following odd behavior of "is.na( )" and hope someone
can give me an explanation
Example:
X1=rep(1:2,5)[-1]
X2=rep(1:5,rep(2,5))[-1]
y= runif(9)
y[3]=NA
xtabs(y~x1+x2)

Now

xtabs(is.na(y)~x1+x2) says that cell 2,2 is NA

   x2
x1  1 2
  1 0 0
  2 0 1
  3 0 0
  4 0 0
  5 0 0

Whereas  

xtabs(!is.na(y)~x1+x2) says that all but cell 1,1 and 2,2 are not NA
   x2
x1  1 2
  1 0 1
  2 1 0
  3 1 1
  4 1 1
  5 1 1	

An explanation will be much appriciated

______________________________________________
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.

________________________________________________________________________
This e-mail has been scanned for all viruses by Star.\ _...{{dropped:12}}



More information about the R-help mailing list