[R] Finding a date 6 months before
sergeyg at gmail.com
Wed Mar 3 13:51:02 CET 2010
Fantastic! Thank you very much for your help, as always!
On Wed, Mar 3, 2010 at 12:24, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> Try this. as.Date(as.yearmon(today) - 6/12) gives the 1st of the
> month 6 months ago and the remainder of that line moves ahead by d-1
> days if its the d-th day of the month now.
>> z <- zoo(0:399, as.Date("2009-06-01")+0:399)
>> today <- Sys.Date(); today
>  "2010-03-03"
>> ago6mos <- as.Date(as.yearmon(today) - 6/12) - 1 + as.numeric(format(today, "%d"))
>> window(z, index = ago6mos)
> If we are at the last day of the month and 6 months ago that month has
> fewer days than today's month then what to do is not well defined but
> we resolve that here by just moving ahead d-1 days anyways.
> On Wed, Mar 3, 2010 at 6:07 AM, Sergey Goriatchev <sergeyg at gmail.com> wrote:
>> Hello everyone
>> I use zoo objects and I need to find a date 6 months before today's date.
>> Example, today we have 3rd March 2010, I need to find the date 3rd
>> September 2009.
>> How could I do that, please?
>> Simplicity is the last step of art./Bruce Lee
>> The more you know, the more you know you don't know.
>> R-help at r-project.org mailing list
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
Simplicity is the last step of art./Bruce Lee
The more you know, the more you know you don't know. /Myself
I'm not young enough to know everything. /Oscar Wilde
Experience is one thing you can't get for nothing. /Oscar Wilde
When you are finished changing, you're finished. /Benjamin Franklin
Luck is where preparation meets opportunity. /George Patten
Kniven skärpes bara mot stenen.
More information about the R-help