Something like: # the third Wednesday m <- as.Date("2014-04-01") format(m+which(format(m+0:30,"%a") == "Wed")[3]-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 Cheers, B. On 2014-04-07, at 1:49 PM, Christofer Bogaso wrote: > Hi, > > 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: > > library(zoo) > 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@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. ______________________________________________ R-help@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.