This function takes a data frame containing year-week and case count and ensures that it includes all possible year-week combinations within the specified range. It fills in missing rows with 0 values for cases and returns the updated data frame.

add_missing_isoweeks(data_agg, date_start = NULL, date_end = NULL)

Arguments

data_agg

An aggregated data frame containing at least the columns 'year','week','cases' representing the isoyear, isoweek and case counts.

date_start

A date object or character of format yyyy-mm-dd. Default is NULL which means that missing isoweeks are added until the minimum date of the dataset. This parameter can be used when the dataset should be extended until the date_start provided.

date_end

A date object or character of format yyyy-mm-dd. Default is NULL which means that missing isoweeks are added until the maximum date of the dataset. This can be used when the dataset should be extended until the date_end provided.

Value

A data frame containing all year-week combinations within the input range, with previously missing year-weeks filled in with 0 values for cases.

Examples

if (FALSE) {
data_agg <- data.frame(
  year = c(2021, 2022, 2022),
  week = c(1, 2, 4),
  cases = c(10, 15, 5)
)
updated_data <- add_missing_isoweeks(data_agg, "2022-01-21", "2023-05-01")
updated_data <- add_missing_isoweeks(data_agg)
updated_data
}