[R] which.min, equal values and fractions

Ivan Krylov kry|ov@r00t @end|ng |rom gm@||@com
Tue Aug 25 14:39:46 CEST 2020


On Tue, 25 Aug 2020 14:26:43 +0200
Mike <mike9 using posteo.nl> wrote:

> But which.min only does so if the values don't contain fractions.
> And I get
> 
> > identical (data3ba, c(2.9,2.9))  
> [1] FALSE
> 
> Why is which.min not always returning 1 but which.max does?

It's the unfortunate consequence of the way floating point numbers
work:

data3ba - 2.9
# [1]  0.000000e+00 -4.440892e-16

See R FAQ 7.31:
https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f

-- 
Best regards,
Ivan



More information about the R-help mailing list