[R] Strange Bug in R
Rolf Turner
r.turner at auckland.ac.nz
Tue Oct 6 10:53:20 CEST 2015
On 06/10/15 21:28, Berend Hasselman wrote:
>
>> On 6 Oct 2015, at 09:24, Neverstop <neverstop at hotmail.it> wrote:
>>
>> Hi all.
>> I don't understand why R works this way:
>>> rm(list=ls())
>>> require(foreign)
>>> dataset <- read.dta("http://www.ats.ucla.edu/stat/data/ologit.dta")
>>> min(dataset$gpa)
>> [1] 1.9
>>> min(dataset$gpa)>=1.90
>> [1] FALSE
>>> min(dataset$gpa)>=1.9
>> [1] FALSE
>>> min(dataset$gpa)>1.89
>> [1] TRUE
>> Shouldn't I get 3 TRUEs?
>> Am I missing something?
>> Thank you.
>>
>>
>
> See R FAQ 7.31 in https://cran.r-project.org/doc/FAQ/R-FAQ.html
> It should provide clarification for your puzzlement.
Not really. The problem is one of the precision to which a floating
point number is *printed* rather than one of the way that floating point
numbers are *calculated*. Hence it is not an instance of the
counter-intuitive nature of floating point arithmetic. I.e. you could
have numbers a and b that were calculated and stored to *infinite*
precision, appear to be equal when printed to some default number of
significant figures, but are not actually equal.
The problems are related and both involve having some understanding of
floating point numbers, but they are not the same problem.
cheers,
Rolf Turner
--
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help
mailing list