Reputation: 149
I want to generate dates within a given range in R that are business days according to some calendar. Much like what you can get when you use panda date_range function with frequency 'b' in Python. Does anyone know of R equivalent?
I was hoping there would be something in zoo/xts but couldn't find.
Upvotes: 2
Views: 2709
Reputation: 1016
library(timeDate)
holidays = holidayNYSE()
daysSeq = as.timeDate(seq(from = as.Date("2016-03-01"), to = as.Date("2016-03-16"), by = "day"))
daysSeq[isBizday(daysSeq, holidays = holidays, wday = 1:5)]
Upvotes: 2
Reputation: 51
I'd recommend checking out the timeDate
package. It has handy functions like isBizday
which you can use to check if a vector of dates are business dates based on a specific calendar.
isBizday(x, holidays = holidayNYSE(), wday = 1:5)
Upvotes: 1