[Rd] Date vs date
Prof Brian Ripley
ripley at stats.ox.ac.uk
Sat Sep 15 09:01:12 CEST 2007
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
More information about the R-devel
mailing list