[R] seq.dates in reverse?

2010-06-29 Thread Jonathan Greenberg
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

__
R-help@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.


Re: [R] seq.dates in reverse?

2010-06-29 Thread Marc Schwartz
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@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.