[R] How to get last day of a month?
Diethelm Wuertz
wuertz at itp.phys.ethz.ch
Mon Sep 14 08:40:51 CEST 2009
jim holtman wrote:
just use timeDate from Rmetrics, there you will find several functions
like ...
# timeLastDayInMonth Computes the last day in a given month and year
# timeFirstDayInMonth Computes the first day in a given month and
year
# timeLastDayInQuarter Computes the last day in a given quarter
and year
# timeFirstDayInQuarter Computes the first day in a given quarter
and year
# timeNthNdayInMonth Computes n-th ocurrance of a n-day in
year/month
# timeLastNdayInMonth Computes the last n-day in year/month
and many more ...
Diethelm Wuertz
> Does this help. Shows how to use the basic functions to get at the answer:
>
>
>> # add first day of month to make it valid
>> x <- as.POSIXct(paste('1', 'sep2009', sep=''), format="%d%b%Y")
>> # now advance one month and then go back one day for the end of the month
>> next.mon <- seq(x, length=2, by='1 month')[2]
>> last.day <- seq(next.mon, length=2, by='-1 day')[2]
>> last.day
>>
> [1] "2009-09-30 GMT"
>
>
>
> On Sun, Sep 13, 2009 at 2:18 PM, megh <megh700004 at yahoo.com> wrote:
>
>> Is there any R function to calculate automatically the last day of a
>> particular month? For example "sep2009" should be converted to last day of
>> September of 2009?
>>
>> Thanks
>> --
>> View this message in context: http://www.nabble.com/How-to-get-last-day-of-a-month--tp25425645p25425645.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> 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.
>>
>>
>
>
>
>
More information about the R-help
mailing list