[R] Truncating dates (and other date-time manipulations)
h.wickham at gmail.com
Thu Sep 11 23:42:10 CEST 2008
On Thu, Sep 11, 2008 at 11:00 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> See ?cut.Date
> In the zoo package see:
> and the many examples in:
> as well as the three zoo vignettes.
> Also in the xts package look at
> For regularly spaced series the tis package supports a wide
> variety of time bases and can convert among them.
> There are as.zoo.tis and as.tis.zoo routines in zoo and tis; also,
> xts is a subclass of zoo so all these packages can work together.
Ok, lets take a concrete example:
dates <- structure(c(8516, 8544, 8568, 8596, 8609, 8666, 8701, 8750, 8754,
8798, 8811, 8817, 8860, 8873, 8918, 8931, 8966, 9020, 9034, 9056
), class = "Date")
 "1993-04-26" "1994-10-18"
I want to be able to say: give me a monthly time series that spans
this range - i.e. it should start on 1993-04-01 and continue to
1994-11-01. I should equally easily be able to say give me a yearly
time series, or every 2 months or every 3 months, or 2 weeks etc.
I don't think that cut.Date helps because I want to make a new series,
not divide up an existing one, similarly with to.period. as.yearmon,
as.yearqtr etc, might be helpful but I'd need to stitch them together
myself and they don't return dates so I'd have to convert back for
plotting. plot.zoo doesn't help because all the examples are regular
More information about the R-help