Message-ID: <20200825153946.1e6ed8ff@trisector>
Date: 2020-08-25T12:39:46Z
From: Ivan Krylov
Subject: which.min, equal values and fractions
In-Reply-To: <20200825122643.GA4321@local>
On Tue, 25 Aug 2020 14:26:43 +0200
Mike <mike9 at 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