Solaris 2.6, R Version 0.63.0 (November 14, 1998) Version 0.62.4 (October 24, 1998)> seq(0.15, 0.70, 0.05)[1] 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 The much reviled (on r-help) 0.62.3 got such simple cases right (even if 0.62.1 did not). Jim Lindsey insisted that such bugs are reported here, so I am. And yes, this is a real example and leads to an incorrect analysis of the dataset in question. The problem is the lines if (by > 0) while (from + n * by > to) n <- n - 1 else while (from + n * by < to) n <- n - 1 One should try to avoid exact comparisons on floating-point quantities. Given the work above to choose a suitable tolerance, we can attach a tolerance here, say if (by > 0) while (from + n * (1 - eps) * by > to) n <- n - 1 else while (from + n * (1 - eps) * by < to) n <- n - 1 although I suspect eps is actually rather too small for safety (I would suggest 10 x machine precision to allow for a number of lfoating point operations). However, I think there is a much simpler approach: n <- as.integer(n + 0.1) # make sure n is not too small tol <- abs(to - from) * 10 * .Machine$double.eps if(by > 0) while(from + n*by > to + tol) n <- n - 1 else while(from + n*by < to - tol) n <- n - 1 Brian -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272860 (secr) Oxford OX1 3TG, UK Fax: +44 1865 272595 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Prof Brian D Ripley <ripley at stats.ox.ac.uk> writes:> Solaris 2.6, R Version 0.63.0 (November 14, 1998) > Version 0.62.4 (October 24, 1998) > > > seq(0.15, 0.70, 0.05) > [1] 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 > > The much reviled (on r-help) 0.62.3 got such simple cases right (even if > 0.62.1 did not).Argh!!!! We've been discussing alternative ways of getting seq right, but didn't get around to follow it through.> although I suspect eps is actually rather too small for safety (I would > suggest 10 x machine precision to allow for a number of lfoating point > operations).The : operator already uses 1e-7... (just like S does)> However, I think there is a much simpler approach: > > n <- as.integer(n + 0.1) # make sure n is not too small > tol <- abs(to - from) * 10 * .Machine$double.eps > if(by > 0) while(from + n*by > to + tol) n <- n - 1 > else while(from + n*by < to - tol) n <- n - 1I've been advocating by*(from/by):(to/by), so as to have the fuzz-fix in one place, and:> .05*(.15/.05):(.70/.05)[1] 0.15 0.20 0.25 0.30 0.35 0.40 0.45 0.50 0.55 0.60 0.65 0.70 Of course one needs to get the sign things right as well... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Seemingly Similar Threads
- Question about subsetting S4 object in ROCR
- problem with heatmap.2 in package gplots generating non-finite breaks
- Problem having tick marks aligned when plotting three graphs on top of one another.
- help - "the condition has length > 1 and only the first element will be used"
- Weird R behaviour?