Skip to contents

Imputes NA values in the 'confirm' column. NA values are replaced with the last available observation or 0.

Usage

enw_impute_na_observations(obs, by = NULL, copy = TRUE)

Arguments

obs

A data.frame with at least 'confirm' and 'reference_date' columns.

by

A character vector of column names to group by. Defaults to an empty vector.

copy

A logical; if TRUE (the default) creates a copy; otherwise, modifies obs in place.

Value

A data.table with imputed 'confirm' column where NA values have been replaced with zero.

Examples

dt <- data.frame(
 id = 1:3, confirm = c(NA, 1, 2),
 reference_date = as.Date("2021-01-01")
)
enw_impute_na_observations(dt)
#> Key: <reference_date>
#>       id confirm reference_date
#>    <int>   <num>         <Date>
#> 1:     1       0     2021-01-01
#> 2:     2       1     2021-01-01
#> 3:     3       2     2021-01-01