From ripley at stats.ox.ac.uk  Sat Sep 15 09:01:12 2007
From: ripley at stats.ox.ac.uk (Prof Brian Ripley)
Date: Sat, 15 Sep 2007 08:01:12 +0100 (BST)
Subject: [Rd] Date vs date
In-Reply-To: <f8e6ff050709141419g5637437bkc52dd809120e7760@mail.gmail.com>
References: <200709141722.l8EHMHF02634@hsrnfs-101.mayo.edu>
	<46EAF699.1010000@biostat.ku.dk>
	<f8e6ff050709141419g5637437bkc52dd809120e7760@mail.gmail.com>
Message-ID: <Pine.LNX.4.64.0709150756500.8538@gannet.stats.ox.ac.uk>

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



[Rd] Date vs date
Prof Brian Ripley