Re: [R] seq.dates in reverse?

From: Marc Schwartz <marc_schwartz_at_me.com>
Date: Tue, 29 Jun 2010 22:05:31 -0500

On Jun 29, 2010, at 7:17 PM, Jonathan Greenberg wrote:

> Pardon the barrage of time series related questions, but another issue
> I'm trying to solve is how to determine a sequence of dates a la
> seq.dates() except going BACKWARDS in time, e.g. if seq.dates()
> allowed for the "to" variables to be set alone, rather than the from=.
> Ultimately, I'd like to have a set of dates preceding a given date in
> predefined intervals (the same ones seq.dates() uses would be fine).
> Thoughts? Would there be an easy way to "reverse engineer" a starting
> date given the "by=" variable and the "length="? With the exception
> of using "by=days", I'm a bit unfamiliar with how to easily determine
> what date was, say, 4 months ago without doing a lot of string hacking
> (seq.dates() conveniently keeps the days of the month constant when
> generate date sequences, which is what I'd like).
>
> --j

Jonathon,

Do you mean something like:

> seq(as.Date("2010-07-29"), length = 2, by = "-4 months")
[1] "2010-07-29" "2010-03-29"

?

Note that the 'by' argument can be a negative interval. See the third bullet in the Details section of ?seq.Date.

HTH, Marc Schwartz



R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Wed 30 Jun 2010 - 03:07:29 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 Jun 2010 - 03:10:43 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive