Learn R Programming

datetimeutils (version 0.6-4)

business_days: Business Days

Description

Check whether a timestamp of class Date or POSIXt is a business day; compute past or future business days.

Usage

is_businessday(x, holidays = NULL)
is_weekend(x)
previous_businessday(x, holidays = NULL, shift = -1)
prev_bday(x, holidays = NULL, shift = -1)
next_businessday(x, holidays = NULL, shift = 1)
next_bday(x, holidays = NULL, shift = 1)

Value

Logical.

Arguments

x

a vector of class Date or POSIXct

holidays

A vector of class Date, or a character vector in a format that is understood by as.Date, or anything that can be coerced to class Date by as.Date (e.g. POSIXt).

shift

integer

Author

Enrico Schumann

Details

is_weekend checks whether a given date is a Saturday or Sunday.

previous_businessday takes a Date x and returns the last non-weekend day before. When shift is less than -1, the function evaluates to the shift-th previous day. When shift is 0, the function will return x if it is a business day, else the previous business day. next_businessday works analogously. There are shorter-named versions next_bday and prev_bday.

References

B.D. Ripley and K. Hornik. Date-Time Classes. R-News, 1(2):8--12, 2001.

See Also

Examples

Run this code
is_weekend(Sys.Date())
previous_businessday(Sys.Date())
next_businessday(Sys.Date())

Run the code above in your browser using DataLab