n_day | R Documentation |
n_day
takes a start date, an end date and a day of the
week. It calculates the number of times said day of the week occurs within
the given time period.
n_day(start, end, day)
start |
The beginning of the time period. Must be a date of |
end |
The end of the time period. Must be a date of |
day |
The day of the week, entered as a |
The Date
and POSIXt
classes within R treat Sunday as
day 0 in a week, and Saturday as day 6. n_day
also treats Sunday as
day 0 (as opposed to day 7) for the sake of consistency.
days_of_week
for returning a vector of the days of the week.
day_to_num
for turning the output from
days_of_week
into numeric form for use within n_day
.
# Number of Tuesdays in January 2018 n_day(lubridate::dmy(01012018), lubridate::dmy(31012018), 2) # Number of Thursdays in 2019 n_day(lubridate::dmy(01012019), lubridate::dmy(31122019), day_to_num("Thu")) # Number of weekdays (Monday-Friday) in 2020 library(magrittr) purrr::map_dbl(1:5, ~ n_day(lubridate::dmy(01012020), lubridate::dmy(31122020), .x)) %>% sum()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.