[R] numeric not equal its value
clint at ecy.wa.gov
Tue May 21 17:22:08 CEST 2013
Not strange. Try with numbers that can be exactly represented in binary
(that's what computers use), e.g.,
Most decimal fractions cannot be represented exactly although a bit of
magic will display them as if they are.
A little digging into the r-help archives will find further explanation.
Clint Bowman INTERNET: clint at ecy.wa.gov
Air Quality Modeler INTERNET: clint at math.utah.edu
Department of Ecology VOICE: (360) 407-6815
PO Box 47600 FAX: (360) 407-7534
Olympia, WA 98504-7600
USPS: PO Box 47600, Olympia, WA 98504-7600
Parcels: 300 Desmond Drive, Lacey, WA 98503-1274
On Mon, 20 May 2013, Jannis wrote:
> Dear R users,
> I ran into the strange situation where a number does not seem to equal its
> value. Try this:
> a <- seq(0.05,0.7,0.05)
> b <- 0.15
> a == b
> Should this not be TRUE? a-b yields a very small number (and not 0) so this
> most probably is a numerical error, but why does seq create such numbers?
> Thanks a lot
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help