Skip to contents

This helper function takes a data.frame or data.table of observations and adds the delay (numeric, in days) between reference_date and report_date for each observation.

Usage

enw_add_delay(obs, timestep = "day", 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).

timestep

The timestep to used. This can be a string ("day", "week", "month") or a numeric whole number representing the number of days.

copy

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

Value

A data.table of observations with a new column delay.

Examples

obs <- data.frame(report_date = as.Date("2021-01-01") + -2:0)
obs$reference_date <- as.Date("2021-01-01")
enw_add_delay(obs)
#>    report_date reference_date delay
#>         <IDat>         <IDat> <num>
#> 1:  2020-12-30     2021-01-01    -2
#> 2:  2020-12-31     2021-01-01    -1
#> 3:  2021-01-01     2021-01-01     0