[R] Number of days in each month

Gabor Grothendieck ggrothendieck at gmail.com
Tue Aug 7 15:19:24 CEST 2007


Just one refinement if you want it nicely formatted:

> ts(diff(seq(as.Date("2007-01-01"), as.Date("2021-01-01"), by = "month")), start = c(2007, 01), freq = 12)
     Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec
2007  31  28  31  30  31  30  31  31  30  31  30  31
2008  31  29  31  30  31  30  31  31  30  31  30  31
2009  31  28  31  30  31  30  31  31  30  31  30  31
2010  31  28  31  30  31  30  31  31  30  31  30  31
2011  31  28  31  30  31  30  31  31  30  31  30  31
2012  31  29  31  30  31  30  31  31  30  31  30  31
2013  31  28  31  30  31  30  31  31  30  31  30  31
2014  31  28  31  30  31  30  31  31  30  31  30  31
2015  31  28  31  30  31  30  31  31  30  31  30  31
2016  31  29  31  30  31  30  31  31  30  31  30  31
2017  31  28  31  30  31  30  31  31  30  31  30  31
2018  31  28  31  30  31  30  31  31  30  31  30  31
2019  31  28  31  30  31  30  31  31  30  31  30  31
2020  31  29  31  30  31  30  31  31  30  31  30  31


On 8/7/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> > diff(seq(as.Date("2007-01-01"), as.Date("2021-01-01"), by = "month"))
> Time differences in days
>  [1] 31 28 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31
>  [26] 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28
>  [51] 31 30 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31
>  [76] 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30
> [101] 31 30 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31
> [126] 30 31 31 30 31 30 31 31 28 31 30 31 30 31 31 30 31 30 31 31 28 31 30 31 30
> [151] 31 31 30 31 30 31 31 29 31 30 31 30 31 31 30 31 30 31
>
>
> On 8/7/07, Lauri Nikkinen <lauri.nikkinen at iki.fi> wrote:
> > Hi R-users,
> >
> >
> >
> > 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).
> >
> >
> >
> > Regards,
> >
> > Lauri
> >
> >        [[alternative HTML version deleted]]
> >
> > ______________________________________________
> > R-help at stat.math.ethz.ch 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