Annotate a dataframe with epiweek and epiyear columns with an epidate column.
Source:R/epiweek_to_date.R
with_epidate.RdAnnotate a dataframe with epiweek and epiyear columns with an epidate column.
Usage
with_epidate(
df,
epiweek_col = "epiweek",
epiyear_col = "epiyear",
epidate_name = "epidate",
day_of_week = 1,
epiweek_standard = "MMWR"
)Arguments
- df
data frame to annotate.
- epiweek_col
Name of the column containing epiweek values. Default
"epiweek".- epiyear_col
Name of the column containing epiyear values. Default
"epiyear".- epidate_name
Name for the output column containing the associated "epidates". Default
"epidate".- day_of_week
Which day of the epidemiological week to use for the epidate. 1-indexed. Passed to
epiweek_to_date(). Default 1 (start date of the epiweek).- epiweek_standard
One of
"MMWR"or"USA"(USA MMWR epiweek, starts on Sunday) and"ISO"(ISO week, starts on Monday). Not case-sensitive. Must be a single value. Default"MMWR".
Examples
tibble::tibble(epiweek = c(1, 2), epiyear = c(2024, 2025)) |>
with_epidate()
#> # A tibble: 2 × 3
#> epiweek epiyear epidate
#> <dbl> <dbl> <date>
#> 1 1 2024 2023-12-31
#> 2 2 2025 2025-01-05
tibble::tibble(epiweek = c(1, 2), epiyear = c(2024, 2025)) |>
with_epidate(day_of_week = 7, epidate_name = "week_ending_date")
#> # A tibble: 2 × 3
#> epiweek epiyear week_ending_date
#> <dbl> <dbl> <date>
#> 1 1 2024 2024-01-06
#> 2 2 2025 2025-01-11
tibble::tibble(epiweek = c(1, 2), epiyear = c(2024, 2025)) |>
with_epidate(day_of_week = c(1, 7))
#> # A tibble: 2 × 3
#> epiweek epiyear epidate
#> <dbl> <dbl> <date>
#> 1 1 2024 2023-12-31
#> 2 2 2025 2025-01-11
tibble::tibble(epiweek = c(1, 2), epiyear = c(2024, 2025)) |>
with_epidate(epiweek_standard = "ISO")
#> # A tibble: 2 × 3
#> epiweek epiyear epidate
#> <dbl> <dbl> <date>
#> 1 1 2024 2024-01-01
#> 2 2 2025 2025-01-06
tibble::tibble(wk = c(1, 2), yr = c(2024, 2025)) |>
with_epidate(epiweek_col = "wk", epiyear_col = "yr")
#> # A tibble: 2 × 3
#> wk yr epidate
#> <dbl> <dbl> <date>
#> 1 1 2024 2023-12-31
#> 2 2 2025 2025-01-05