0

I remember coming across this issue in the past but I cannot find the solution anymore.

For a dataframe with the numeric column a I want to find the row for which a = 27.99. View the dataframe I know that in row 100 this is the case.

So:

> df$a[100]
27.99

> df$a[100] == 27.99
FALSE

> which(df$a == 27.99)
integer(0)

> is.numeric(df$a[100])
TRUE

I remember it might have to do with machine precision.

Pascal
  • 563
  • 1
  • 3
  • 15

1 Answers1

0

Could be an issue with floating points, try:

which(round(df$a) == 28)

see: floating point issue in R? also this has a very thorough explanation: Why are these numbers not equal?

MatthewR
  • 2,660
  • 5
  • 26
  • 37