How to figure third Friday of a month in R

后端 未结 4 1445
日久生厌
日久生厌 2020-12-06 15:36

I\'m trying to figure out of how to create a vector of dates of third Fridays of a month for the past 3 years

Thank you in Advance

4条回答
  •  攒了一身酷
    2020-12-06 16:07

    To round it off, here's a messy way to do it with base functions:

    d <- seq(as.Date("2000/1/1"), by = 1, length.out = 500)
    sort(as.Date(tapply(d[which(format(d, '%a')=='Fri')], 
                        format(d[which(format(d, '%a')=='Fri')], '%m-%Y'),
                        function(x) x[3]), origin='1970-01-01'))
    

提交回复
热议问题