[R] "match" and "which" give NA for some values, but not others

Heemun Kwok heemun at u.washington.edu
Wed Jul 27 05:50:14 CEST 2011


Hello list,
I am having trouble with "match" and "which" giving a NA result for some values, but not others.  Here is a simple example:

> aaa <- seq(0,1,by=0.05)

> aaa
 [1] 0.00 0.05 0.10 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70
[16] 0.75 0.80 0.85 0.90 0.95 1.00

> match(0.5,aaa)
[1] 11

> match(0.6,aaa)
[1] NA

> which(aaa==0.5)
[1] 11

> which(aaa==0.6)
integer(0)

> sessionInfo()
R version 2.12.2 (2011-02-25)
Platform: i386-pc-mingw32/i386 (32-bit)

Am I missing something? Any thoughts?

Thank you,
Heemun


-------------------------------------------
Heemun Kwok, MD, MS
Acting Instructor, Emergency Medicine
University of Washington School of Medicine

Box 359702
325 Ninth Avenue
Seattle, WA 98104
Tel: 206-744-8461
Fax: 206-744-4097
Email: Heemun at uw.edu



More information about the R-help mailing list