[R] Number of days in each month

Dirk Eddelbuettel edd at debian.org
Tue Aug 7 15:06:45 CEST 2007


On Tue, Aug 07, 2007 at 03:53:28PM +0300, Lauri Nikkinen wrote:
> What is the best way to achieve a table which contains all days and months
> between years 2007-2020? I would like to calculate number of days in each
> month within those years (to data frame).

Here you go -- just replace length.out=3 by 24*12 for your twentyfour years:

   > as.POSIXlt(seq(as.Date("2007-02-01"), by="month", length.out=3)-1)$mday
  [1] 31 28 31
  > 

A sequence of month at the first of the next month, shifted back a day
gives the last one of that month -- converted to POSIXlt from which we
extract the day-of-the-month.

Hth, Dirk

-- 
Three out of two people have difficulties with fractions.



More information about the R-help mailing list