[R] Getting a particular weekday for a given month
boris.steipe at utoronto.ca
Mon Apr 7 20:23:55 CEST 2014
# the third Wednesday
m <- as.Date("2014-04-01")
format(m+which(format(m+0:30,"%a") == "Wed")-1, "%a %b %d")
# or eg. all Tuesdays
format(m+which(format(m+0:30,"%a") == "Tue")-1, "%a %b %d")
# or eg. the last Friday
wd <- which(format(m+0:30,"%a") == "Fri")-1
format(m+wd[length(wd)], "%a %b %d")
Note: adding integers to your "Month" increments months, not days
On 2014-04-07, at 1:49 PM, Christofer Bogaso wrote:
> Given a month name, I am looking for some script to figure out, what is the
> date for 3rd Wednesday. For example let say I have following month:
> Month <- as.yearmon(as.Date(Sys.time()))
> I need to answer: What is the date for 3rd Wednesday of 'Month'?
> Really appreciate for any pointer.
> Thanks for your time.
> [[alternative HTML version deleted]]
> 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.
More information about the R-help