Skip to content
Prev 163716 / 398506 Next

date operations

On Wed, 2008-12-03 at 13:18 -0500, Gabor Grothendieck wrote:
It also works if you flip the ordering:
[1] "2009-02-15"
Warning message:
Incompatible methods ("+.Date", "Ops.difftime") for "+"

It is just a warning, but one should check that the answer is correct
given the perceived problem with different classes of objects. 

Why it works is not odd if you look at the help for ?`+.Date`, which
shows that for this method (correct term?) we need 'date' + 'x', where
'date' is an object of class Date and 'x' is numeric.

The OP can avoid the warning by:
[1] "2009-02-15"

If you put alpha1 first (class difftime) that method gets used and
alpha2 is coerced to numeric to complete the operation:
Time difference of 14290 days
Warning message:
Incompatible methods ("Ops.difftime", "+.Date") for "+"
[1] 14290

To answer the OP's question about conversion, no you don't need to
convert Date objects to numerics to work with them. You just need to be
aware of method dispatch for `+()` and check that adding objects of
differing classes makes sense.

Of course, this assumes that the OP wanted the answer as an object of
class "Date"...?

G