cepiweek: Generate Continuous Epidemiological Week Index for a Date...

View source: R/cepiweek.R

cepiweekR Documentation

Generate Continuous Epidemiological Week Index for a Date Column

Description

This function adds a continuous epidemiological week index to a data frame by assigning each date to a sequential week number starting from a reference date.

Usage

cepiweek(data, col_date, start = NULL, format = "dmy")

Arguments

data

A data frame containing the date column.

col_date

Name of the date column (string).

start

Optional start date for counting weeks (Date or string). Defaults to the minimum date in the column col_date.

format

Optional date format flag. Use "mdy" if all dates are in month-day-year format (common in US). Defaults to "dmy"/"ymd" which handles day-month-year or year-month-day formats.

Details

The generated weeks are continuous and do not reset at calendar year boundaries. They are not ISO 8601 or MMWR weeks. This function is intended for epidemiological modeling, time-series analysis, and nowcasting applications.

You can specify a start date for counting weeks; if none is provided, the minimum date in the column is used. The function also allows specifying the format of the dates to handle different conventions (day-month-year vs month-day-year).

  • The function automatically replaces / with - for consistency.

  • If any dates cannot be converted, the function stops with an error.

  • A warning is issued if the start date is after the earliest date in the column.

  • Continuous weeks are aligned to Mondays.

Value

A data frame with an added cepiweek column containing continuous week indices.

See Also

GitHub page of the package.

Examples

# Standard dmy/ymd dates
k <- data.frame(
  num = c(1, 2, 3),
  date = c("15-01-2024", "12/02/2025", "2026-08-01")
)
cepiweek(k, col_date = "date")

# American format mm-dd-yyyy
k2 <- data.frame(
  num = c(1, 2, 3),
  date = c("01/15/2024", "02-12-2025", "08/01/2026")
)
cepiweek(k2, col_date = "date", format = "mdy")


cepiweek documentation built on Feb. 19, 2026, 5:07 p.m.