[R] Strange Bug in R

Rolf Turner r.turner at auckland.ac.nz
Tue Oct 6 10:11:28 CEST 2015


On 06/10/15 20:24, Neverstop 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?

No.

> Am I missing something?

Comprehension of significant digits and the storage of floating point 
numbers.

Try:

    print(min(dataset$gpa),digits=10)

Please don't refer to phenomena as "bugs" unless you are really sure 
that they are not simply instances of things that you don't understand.
R was designed and written by very clever people and has been used, 
tested and pushed to its limits by a wide variety of users for over 20 
years.  It is highly improbable that you would stumble upon a real bug 
in such a simple context.

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