[Rd] Inaccuracy in seq() (PR#9189)

Roger Bivand Roger.Bivand at nhh.no
Wed Aug 30 13:43:53 CEST 2006


On Wed, 30 Aug 2006 kellymj1 at cf.ac.uk wrote:

> Full_Name: Mark James Kelly
> Version: 2.3.1
> OS: Windows
> Submission from: (NULL) (193.63.127.224)
> 
> 
> Sequence produces slightly inaccurate results. 

Not a bug, but a FAQ (7.31):

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

Try:

otherthing[25]==thingnor[3]
identical(otherthing[25], thingnor[3])
all.equal(otherthing[25], thingnor[3])

?all.equal


> 
> #This (supposedely) creates a sequence 0.060,0.065,0.070.....0.30
> thingnor=(seq(0.06,0.30,by=0.005))
> 
> #This does the same but rounds to three decimals
> thingrou=round(seq(0.06,0.30,by=0.005),3)
> 
> #This is another vector, the same length as the two above, with 24 zeroes, then
> 0.070, then 24 zeroes
> otherthing=c(rep(0,24),0.070,rep(0,24))
> 
> 
> #This fails to select the entries equal to 0.070 
> otherthing[otherthing==thingnor[3]]
> 
> #This gives the correct answer
> otherthing[otherthing==thingrou[3]]
> 
> 
> #This compares the two sequences (which should be identical)
> (thingnor-thingrou)
> 
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
> 

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-devel mailing list