On Fri, Nov 7, 2008 at 3:32 AM, Barry Rowlingson <[EMAIL PROTECTED]> wrote: > 2008/11/7 tedzzx <[EMAIL PROTECTED]>: >> >> The problem is that: There is some rounding problems, for example >> Library(chron) >> any(times("4:00:01")==times("4:00:00")+times("00:00:01"))) >> False >> >> But,it should be true > > FAQ 7.31 in disguise! > > chron stores date-times as fractions, so you're comparing two > floating point numbers here. FAQ 7.31 applies. > > Use 'all.equal', which has a method for chron that uses a 1 second > tolerance to match times: >
That solution works but just to be precise, note that a "times" class object need not be a "dates" or "chron" class object and while there is a chron:::all.equal.dates there is no chron:::all.equal.times. The reason all.equal works here is that all.equal.default works here and it works here by ultimately calling all.equal.numeric to do the real work. > y <- times("4:00:00")+times("00:00:01") > class(y) # no "dates" or "chron" in class vector [1] "times" Also all.equal.dates uses a tenth of a second as the tolerance: > chron:::all.equal.dates function (..., tolerance = 1/(10 * 24 * 60 * 60)) NextMethod("all.equal", ..., tolerance = tolerance) <environment: namespace:chron> >> all.equal(times("4:00:01"),times("4:00:00")+times("00:00:01")) > [1] TRUE > ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.