Getting sequence of business days between pairs of days

Here is how to get sequence of business days between pairs of days in a data frame.

Let’s say you have a data frame which has pairs of start day and end day like this, and you want to get sequence of business days between those days, for each row of this data frame.


Since we are going to make use of bizdays package, we need to define a calendar for it first.
This can be done by a script like following, for example.

holidays <- as.character(c("2019-07-04", "2019-09-02", "2019-10-14")) #4th of July and Labor day and Columbus day

                         holidays=holidays, weekdays=c('sunday', 'saturday'),
TRUE #This is just to pass validation of this script.

Now back to the data frame, group the rows of the data frame, though in this case one group consists of only one row.

Then, making use of do function and bizseq function in a custom R step like following, we can create a data frame with sequences of business days for each row of the original data frame.

do(data.frame(days=bizdays::bizseq(.$start, .$end, "MyCalendar")))

For your convenience to reproduce this, here is an Exploratory project which includes the script and steps described here.

I included another way to do it with nest/unnest and purrr::map function, which is a little more lengthy but more modern in this project too.

Awesome work! Works perfectly…


If your end date range is greater than the last date in your holiday calendar, bizseq returns a Date range error.

Thank you for pointing that out, Tony!

I just updated the calendar definition to specify and explicitly, so that holidays does not have to cover the range of data.