CRAN downloads CRAN status

cepiweek

Description

cepiweek adds a continuous epidemiological week index to a data frame, based on a date variable.

Important

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.

Installation

# 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

Usage

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.

License

This package is licensed under the MIT License. See LICENSE for details.