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
|