Is there an R package that will handle POSIX objects and return the nth N-day of the week?

后端 未结 2 1840
故里飘歌
故里飘歌 2021-01-16 12:13

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

2条回答
  •  無奈伤痛
    2021-01-16 13:10

    The timeDate package has some of that functionality; I based this little snippet of code on some code that package. This is for Dates, 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")
    }
    

提交回复
热议问题