s-news
[Top] [All Lists]

Re: comparing NA values

To: "Dave Evens" <devens8765@yahoo.com>
Subject: Re: comparing NA values
From: "Dimitris Rizopoulos" <dimitrios.rizopoulos@student.kuleuven.ac.be>
Date: Tue, 14 Jun 2005 13:46:52 +0200
Cc: <s-news@lists.biostat.wustl.edu>
References: <20050614113815.59566.qmail@web61324.mail.yahoo.com>
What I proposed is based on the position of NAs, so probably it will work. However, note that floating point comparisons are tricky, see e.g.,

4.15 - 3.15 == 1
all.equal(1, 4.15 - 3.15)


I hope it helps.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/
    http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm


----- Original Message ----- From: "Dave Evens" <devens8765@yahoo.com> To: "Dimitris Rizopoulos" <dimitrios.rizopoulos@student.kuleuven.ac.be>
Sent: Tuesday, June 14, 2005 1:38 PM
Subject: Re: [S] comparing NA values



Is it possible with floating points?

Thanks in advance

Dave


--- Dimitris Rizopoulos
<dimitrios.rizopoulos@student.kuleuven.ac.be> wrote:

or maybe something like this:

x <- c(1:10, 1:10, rep(NA, 20))
y <- c(1:30, rep(NA, 10))
################
ind <- as.logical( (is.na(x) | is.na(y)) - (is.na(x)
& is.na(y)) )
out <- x == y
out[ind] <- FALSE
out

could also work.

Best,
Dimitris

----
Dimitris Rizopoulos
Ph.D. Student
Biostatistical Centre
School of Public Health
Catholic University of Leuven

Address: Kapucijnenvoer 35, Leuven, Belgium
Tel: +32/16/336899
Fax: +32/16/337015
Web: http://www.med.kuleuven.ac.be/biostat/


http://www.student.kuleuven.ac.be/~m0390867/dimitris.htm



----- Original Message ----- From: "Petr Pikal" <petr.pikal@precheza.cz>
To: "Dave Evens" <devens8765@yahoo.com>;
<s-news@lists.biostat.wustl.edu>
Sent: Tuesday, June 14, 2005 1:03 PM
Subject: Re: [S] comparing NA values


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

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






__________________________________
Discover Yahoo!
Stay in touch with email, IM, photo sharing and more. Check it out!
http://discover.yahoo.com/stayintouch.html



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