s-news
[Top] [All Lists]

Re: comparing NA values

To: Dave Evens <devens8765@yahoo.com>, s-news@lists.biostat.wustl.edu
Subject: Re: comparing NA values
From: "Petr Pikal" <petr.pikal@precheza.cz>
Date: Tue, 14 Jun 2005 13:03:41 +0200
In-reply-to: <20050614102444.61907.qmail@web61325.mail.yahoo.com>
Hi

On 14 Jun 2005 at 3:24, Dave Evens wrote:

> 
> Is it possible to make comparisons between numeric NAs
> and other numeric values?

everything is possible but I think you will need a special function.

e.g.

mytest<-function(x,y) {
d<-length(x)
testvec1<-is.na(x)+is.na(y)
firstno<-which(x[testvec1==0]==y[testvec1==0])
secondno<-which(testvec1==2)
thirdno<-which(testvec1==1)

result<-rep(F,d)
result[firstno]<-T
result[secondno]<-NA
result[thirdno]<-F
result
}

Which works with integers , but could give some wrong results 
with floating point numbers.

HTH
Petr



> 
> For example, if I have two vectors
> 
> > x<-c(1:10,1:10,rep(NA,20))
> > y<-c(1:30,rep(NA,10))
> 
> I want to compare them
> 
> > x==y
>  [1]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE 
> TRUE  TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
> FALSE FALSE FALSE    NA    NA    NA    NA    NA
> [26]    NA    NA    NA    NA    NA    NA    NA    NA  
>  NA    NA    NA    NA    NA    NA    NA
> 
> What I would like is to have TRUE for the first 10,
> FALSE for the next 20, and NA for the last 10. Is this
> possible?
> 
> Thanks in advance for any help.
> 
> Dave
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Tired of spam?  Yahoo! Mail has the best spam protection around 
> http://mail.yahoo.com 
> --------------------------------------------------------------------
> This message was distributed by s-news@lists.biostat.wustl.edu.  To
> unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
> the BODY of the message:  unsubscribe s-news

Petr Pikal
petr.pikal@precheza.cz



<Prev in Thread] Current Thread [Next in Thread>