Provides a simple algorithm to generate a continuous epidemiological week index from date variables in a data frame. Weeks are computed as sequential 7-day intervals aligned to Mondays, starting from the earliest observed date or from a user-supplied start date. They do not reset at calendar year boundaries and are not ISO 8601 nor MMWR calendar weeks. Missing or non-convertible dates are returned as NA instead of stopping the computation. The approach is intended for epidemiological modeling and time-series analysis where temporal continuity is required.
cepiweek adds a continuous epidemiological week index to a data frame, based on a date variable.
The weeks generated by cepiweek are continuous indexed weeks. They are not ISO 8601 nor MMWR calendar weeks.
Weeks are 7-day intervals aligned on Mondays, counted from the earliest observed date (or from a start date),
and they do not reset at calendar year boundaries.
They are intended for time-series analysis and epidemiological modeling.
# Official method (CRAN)
install.packages("cepiweek")
# From GitHub, method 1
# install.packages("devtools")
devtools::install_github("DanielDegina/cepiweek")
# From GitHub, method 2
# install.packages("remotes")
remotes::install_github("DanielDegina/cepiweek")
# Method 3: download the ZIP file, extract it, then in R:
devtools::install("path/to/cepiweek") # directory where you placed the package
library(cepiweek)
k = data.frame(
num = 1:4,
date = c("15-01-2024", "12/02/2025", NA, "2026-08-01")
)
# dmy / ymd dates (default); missing or non-convertible dates give NA
cepiweek(k, col_date = "date")
# American format (month-day-year)
cepiweek(k, col_date = "date", format = "mdy")
# Same origin for several columns: fix the start date
cepiweek(k, col_date = "date", start = "2024-01-01")
# Silence the warning about non-convertible dates
cepiweek(k, col_date = "date", quiet = TRUE)
The date column can be of class Date, POSIXct or character. Missing values, empty strings,
"NA" and dates that cannot be converted are returned as NA.
This package is licensed under the MIT License. See LICENSE for details.