[R] number of Mondays

Gabor Grothendieck ggrothendieck at gmail.com
Thu Jan 15 20:45:18 CET 2009


Try this:

> library(zoo) # as.yearmon
> dd <- seq(as.Date("2000-01-01"), as.Date("2004-12-31"), "day")
> dow <- as.numeric(format(dd, "%w"))
> ym <- as.yearmon(dd)
> tab <- do.call(rbind, tapply(dow, ym, table))
> rownames(tab) <- format(as.yearmon(as.numeric(rownames(tab))))
> head(tab)
         0 1 2 3 4 5 6
Jan 2000 5 5 4 4 4 4 5
Feb 2000 4 4 5 4 4 4 4
Mar 2000 4 4 4 5 5 5 4
Apr 2000 5 4 4 4 4 4 5
May 2000 4 5 5 5 4 4 4
Jun 2000 4 4 4 4 5 5 4


On Thu, Jan 15, 2009 at 2:28 PM, Carlos Hernandez <carlos.uni2 at gmail.com> wrote:
> dear All,
> i'm trying to calculate the number of Mondays, Tuesdays, etc that each month
> within a date range has. I have time series data that spans 60 months and i
> want to calculate the number of Mondays, Tuesdays, Wed, etc of each month.
> (I want to control for weekly seasonality but my data is monthly).
>
> Is there an easy way to to this in R? or is there a package i could use? i
> did some quick search in the help files and R sites but could not find any
> answers.
>
> i appreciate any hint you could give,
>
> thanks.
>
> Carlos
>
> ______________________________________________
> 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