Reporting almost always slows down at the weekend, which is one of the strongest and most predictable patterns in surveillance data. This tells you which days are which, and lets you say what "weekend" means – it is Friday and Saturday in much of the Middle East, and Sunday alone in some countries.
Usage
is_weekday(date, weekend_days = c("Sat", "Sun"))Arguments
- date
A Date (or POSIXt) object. May be a vector.
- weekend_days
A character or numeric vector defining which days count as the weekend. Defaults to Saturday and Sunday.
Character: day names or abbreviations, case-insensitive –
c("Mon", "Tuesday", "wed", ...). English names always work, whatever the session's locale is, and so do the names of the current locale, with or without their accents – underLC_TIME = "es_ES"bothc("Sat", "Sun")andc("sáb", "dom")mean the weekend.Numeric: integers 1-7 in
lubridate::wday()numbering withweek_start = 1, so 1 = Monday and 7 = Sunday.
See also
temporal_effects() and add_temporal_effects(), which use this to build the
day-of-week and weekend terms a model can fit;
plot_day_of_week_effects() to see the effect in the
data; align_weeks(), whose align_on_day uses this same ISO numbering.
Examples
is_weekday(as.Date("2020-04-22")) # TRUE (Wed)
#> [1] TRUE
is_weekday(as.Date("2020-04-19")) # FALSE (Sun)
#> [1] FALSE
## Middle East weekend (Fri - Sat)
is_weekday(as.Date("2020-04-17"), weekend_days = c("Fri", "Sat"))
#> [1] FALSE
# Weekend only on Friday
is_weekday(as.Date("2020-04-17"), weekend_days = "Friday")
#> [1] FALSE
is_weekday(as.Date("2020-04-18"), weekend_days = "Friday")
#> [1] TRUE
## Weekend on Sun - Mon (numeric: 7 = Sun, 1 = Mon)
is_weekday(as.Date("2020-04-20"), weekend_days = c(7, 1))
#> [1] FALSE
## Day names of the session's own locale are understood too
locale_weekend <- format(as.Date(c("2020-04-18", "2020-04-19")), "%a")
is_weekday(as.Date("2020-04-18"), weekend_days = locale_weekend)
#> [1] FALSE
