Here is some basic code and its output. I really can’t say anything more than a logical test for a sequence containing 1.2 is giving an inaccurate result. It is working for many other values.
# Incorrect
> seq(0.5, 1.5, by=0.05) == 1.2
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
# Correct
> seq(0.5, 1.5, by=0.05) == 1.15
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
# Correct
> seq(0.5, 1.5, by=0.05) == 1.25
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE FALSE
# Correct
> seq(0.5, 1.5, by=0.05) == 1.3
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[13] FALSE FALSE FALSE FALSE TRUE FALSE FALSE FALSE FALSE
I tried testing all the values using the following, which does not reproduce the bug:
> sapply(seq(0.5, 1.5, by=0.05), function(x){sum(seq(0.5, 1.5, by=0.05) == x)})
[1] 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
I’m using R version 2.13.2 (2011-09-30), Platform: x86_64-pc-linux-gnu (64-bit).
You can duplicate what all.equal is doing by writing a comparison function of your own:
then you can do which(is.nearenough(s,1.2)) where s is your sequence. You may need to tweak the tolerance for your application.