
Convert epidemiological (or ISO) week/year to aligned dates
week_2_date.RdTakes week numbers and year numbers and returns the date corresponding to a specified weekday within that week. This is typically used for aligning epiweek or isoweek data to a consistent weekday.
Arguments
- .data
A data.frame or tibble.
- week_col
tidy-select column name containing epidemiological week numbers.
- year_col
tidy-select column name containing epidemiological year numbers.
- align_on_day
Integer 1–7 (
lubridate::wday()numbering) indicating the weekday to align to.- week_fun
Function that extracts week numbers from a date (either
lubridate::epiweek(),lubridate::isoweek()).- year_fun
Function that extracts the epidemiological/ISO year from a date (either
lubridate::epiyear()orlubridate::isoyear()).- date_col_name
Name of the resulting date column.
Examples
df <- data.frame(
epidemiological_week = 1:5,
epidemiological_year = rep(2024, 5)
)
df |>
week_2_date(
week_col = epidemiological_week,
year_col = epidemiological_year
)
#> epidemiological_week epidemiological_year date
#> 1 1 2024 2023-12-31
#> 2 2 2024 2024-01-07
#> 3 3 2024 2024-01-14
#> 4 4 2024 2024-01-21
#> 5 5 2024 2024-01-28