[Rd] Date vs date

hadley wickham h.wickham at gmail.com
Fri Sep 14 23:19:44 CEST 2007


> >   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")).

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.

Hadley



More information about the R-devel mailing list