[R] a problem with is.na

René Holst rene at constat.dk
Wed Jan 26 12:04:49 CET 2011


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



More information about the R-help mailing list