0

The problem is which() function doesn't work properly. Bizzare problem occurs in R:

This code:

percentile.range<-(seq(0.32,1,0.01))

which(percentile.range==.59)

Returns:

integer(0)

And

percentile.range<-(seq(0.32,1,0.01))

which(percentile.range==.61)

Returns

30

This is beyond me, how such a simple statement doesn't produce a desirable result? Did I miss anything?

Community
  • 1
  • 1
Vivaldi
  • 138
  • 5
  • 1
    `percentile.range[which(percentile.range>=.5899 & percentile.range<=.59001)]`. Look at [this](https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal) – simone May 31 '17 at 14:32
  • That solves my problem. Thanks – Vivaldi May 31 '17 at 14:34
  • 1
    I prefer this approach to compare 2 floating point numbers : `abs(percentile.range - 0.59) <= 1e-12 (or another tolerance value)` – digEmAll May 31 '17 at 14:36
  • Thanks @digEmAll that solves my problem. If you put it in the answer I will accept it. – Vivaldi May 31 '17 at 14:41

0 Answers0