[R] Truncating dates (and other date-time manipulations)

Gabor Grothendieck ggrothendieck at gmail.com
Fri Sep 12 04:52:53 CEST 2008


On Thu, Sep 11, 2008 at 10:43 PM, hadley wickham <h.wickham at gmail.com> wrote:
>> The problem is trying to force everything into Date class.  If you really
>> want a monthly series you probably want yearmon rather than Date
>> class
>
> Could you give a bit more detail about why you think this is the best
> way to proceed?  To me, it seems like it's easiest to have one date
> class which you use regardless of the underlying accuracy of the
> series (obviously in a date class the lowest level of discrimination
> will be a single day).

That way all the methods that operate on it can specifically be
taylored to that class.  Working with monthly series is trivial
if they are of yearmon class since the next month can be obtained
by adding 1/12 instead of some weird number of days, the number
of months between two dates is just 12 * (ym2 - ym1), etc.  Even
in the examples given in my last post in this thread look at
how much simpler the yearmon examples were than the Date
based examples.
Working with dates when you really want months is just
much needlessly complex and the benefit of having a single Date class
just seems not worth it when R's oo capability is already in place to
leverage.



More information about the R-help mailing list