The package bizdays
has the function offset
which offsets the given dates by a number of business days.
It relies on the calendar you define and of course you can define a calendar where weekends are the only nonworking days.
Here is an example:
library(lubridate)
library(bizdays)
cal <- Calendar(weekdays=c('saturday', 'sunday'))
date.in <- dmy(c("30-8-2001", "12-1-2003", "28-2-2003", "20-5-2004"))
bizdays::offset(date.in, 6, cal)
# [1] "2001-09-07" "2003-01-21" "2003-03-10" "2004-05-28"
2018 Update
The function Calendar
in bizdays
has been renamed to create.calendar
,
but (in April 2018) a warning is no longer issued.
The code should now be slightly different:
library(lubridate)
library(bizdays)
create.calendar(name="mycal", weekdays=c('saturday', 'sunday'))
date.in <- dmy(c("30-8-2001", "12-1-2003", "28-2-2003", "20-5-2004"))
bizdays::offset(date.in, 6, "mycal")
# [1] "2001-09-07" "2003-01-21" "2003-03-10" "2004-05-28"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…