Skip to contents

Add the maximum number of cases reported on a given day to the data set. This is useful for calculating the proportion of cases reported on a given day which is also done in this function.

Usage

enw_add_max_reported(obs, copy = TRUE)

Arguments

obs

A data.frame containing at least the following variables: reference date (index date of interest), report_date (report date for observations), and confirm (cumulative observations by reference and report date).

copy

Should obs be copied (default) or modified in place?

Value

A data.table with a max_confirm and cum_prop_reported

columns added. max_confirm is the maximum number of cases reported on a given day. cum_prop_reported is the proportion of cases reported on a given day relative to the maximum number of cases reported on a given day.

Examples

obs <- data.frame(report_date = as.Date("2021-01-01") + 0:2)
obs$reference_date <- as.Date("2021-01-01")
obs$confirm <- 1:3
enw_add_max_reported(obs)
#>    reference_date .group max_confirm report_date confirm cum_prop_reported
#> 1:     2021-01-01      1           3  2021-01-01       1         0.3333333
#> 2:     2021-01-01      1           3  2021-01-02       2         0.6666667
#> 3:     2021-01-01      1           3  2021-01-03       3         1.0000000