Skip to content
Prev 26132 / 63424 Next

Date vs date

Terry Therneau wrote:
The ideology here is that the origin is an implementation detail which 
users are not really expected to know. as.Date("1960-1-1")+10  works, 
and if you insist, so does structure(10, class="Date") (albeit not with 
the same result).
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")).
Same story as above. It is assumed that the divisor is unit-less. 
Convert to numeric first to avoid this. (The idea has been raised to 
introduce new units: epiyears and epimonths, in which case you might do

x <- as.Date('2007-9-14') - as.Date('1953-3-10')
units(x) <- "epiyears"

which would give you the age in years for those purposes where you don't 
care missing the exact birthday by a day or so.)
Yes. Also: this _is_ ambiguous, but does not cause an error

 > as.Date("05-06-07")
[1] "5-06-07"

Not that it should or even could, but it demonstrates that the error 
message above is beside the point.  Can you suggest a better wording?