Re: [R] How to manipulate the time data without the date?

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Fri, 07 Nov 2008 06:12:48 -0500

On Fri, Nov 7, 2008 at 3:32 AM, Barry Rowlingson <b.rowlingson_at_lancaster.ac.uk> wrote:
> 2008/11/7 tedzzx <zengzhenxing@gmail.com>:
>>
>> 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_at_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. Received on Fri 07 Nov 2008 - 11:15:22 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 07 Nov 2008 - 12:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive