Re: [Rd] Date vs date

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Sat, 15 Sep 2007 08:01:12 +0100 (BST)

On Fri, 14 Sep 2007, hadley wickham wrote:

>>>   3. temp <- as.Date('1990/1/1') - as.date('1953/2/5')
>>>      sqrt(temp)
>>>      Error in Math.difftime(temp3) : sqrtnot defined for "difftime" objects
>>>
>>>   Minor bug: no space before the word 'not'
>>>   Major: this shouldn't fail.
>>>
>>>

>> Arguably, it should (Is this a difftime object? Which units?).
>> I'd advise against numeric operation on difftime objects in general,
>> because of the unspecified units. These are always "days" when working
>> with Date objects, but with general time objects it is not predictable.
>> So I'd recommend sqrt(as.numeric(temp, units="days")).

It fails by design. Using sqrt() on a measurement that has an arbitrary origin would not have been good design.

> Why not just always use seconds for difftime objects?  An attribute
> could control how it was formatted, but would be independent of the
> underlying representation.

Because of leapseconds and changes to/from DST (which require knowing the timezone and its transition times).

-- 
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 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Received on Sat 15 Sep 2007 - 07:04:41 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 Sun 16 Sep 2007 - 02:41:14 GMT.

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