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
  • 47,396
  • 5
  • 31
  • 61
user0
  • 2,517
  • 8
  • 24
  • 62
  • 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
  • 47,396
  • 5
  • 31
  • 61