I have written a function which, when provided a range of dates, the name of a particular day of the week and the occurrence of that day in a given month (for instance, the
The timeDate
package has some of that functionality; I based this little snippet of code on some code that package. This is for Date
s, timeDate has underlying POSIX types.
nthNdayInMonth <- function(date,nday = 1, nth = 1){
wday <- (as.integer(date) - 3) %% 7
r <- (as.integer(date) + (nth -1) * 7 + (nday - wday)%%7)
as.Date(r,"1970-01-01")
}