sdeveloper
sdeveloper

Reputation: 149

Business Day dates sequence in R

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

Answers (2)

nesvarbu
nesvarbu

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

Joe R
Joe R

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

Related Questions