Strange results using match and which function
R FAQ 7.31 . -- Bert
On Mon, Nov 4, 2013 at 10:29 AM, Timo Schmid <timo_schmid at hotmail.com> wrote:
Hello, I want to match specific numbers and a vector. Therefore I use the match or which function but I get unreasonable results. Has anybody an idea why I got a NA inmatch(0.12, tau)Please see the code below:
tau<-seq(0.02,0.98,0.02) tau
[1] 0.02 0.04 0.06 0.08 0.10 0.12 0.14 0.16 0.18 0.20 0.22 0.24 0.26 0.28 0.30 0.32 0.34 0.36 0.38 0.40 [21] 0.42 0.44 0.46 0.48 0.50 0.52 0.54 0.56 0.58 0.60 0.62 0.64 0.66 0.68 0.70 0.72 0.74 0.76 0.78 0.80 [41] 0.82 0.84 0.86 0.88 0.90 0.92 0.94 0.96 0.98
match(0.02, tau)
[1] 1
match(0.12, tau)
[1] NA
match(0.16, tau)
[1] 8
which(0.12==tau)
integer(0)
which(0.16==tau)
[1] 8
0.14%in%tau
[1] FALSE
0.16%in%tau
[1] TRUE
Thanks in advance
Timo
[[alternative HTML version deleted]]
______________________________________________ R-help at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.
Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374