1

I am making a simple sequence. Why is this true?

Browse[1]> seq(7.4, 12.7, 0.001)[2] == 7.401
[1] FALSE
Browse[1]> seq(7.4, 12.7, 0.001)[2] == '7.401'
[1] TRUE
Sotos
  • 51,121
  • 6
  • 32
  • 66
Sam Weisenthal
  • 2,791
  • 9
  • 28
  • 66
  • Never use `==` to compare numerics in R. Check [this](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f) out. – 989 Sep 24 '18 at 14:27

1 Answers1

2

That is a floating point (tolerance) error. Try,

round(seq(7.4, 12.7, 0.001)[2], 3) == 7.401
#TRUE
Sotos
  • 51,121
  • 6
  • 32
  • 66