
Filter reference dates that precede the earliest report date
Source:R/preprocess.R
enw_filter_reference_dates_by_report_start.RdRemoves observations where the
reference_date is earlier than the minimum
report_date within each group. Rows with missing
reference_date are retained. This is useful for
ensuring that observations are only included from the
first available report date onwards.
This function is typically called before
enw_add_incidence() so that the incidence calculation
starts from a valid reporting window. Without this
step, reference dates that predate any report date
produce spurious leading entries in the incidence
output.
Arguments
- obs
A
data.framewithreference_dateandreport_datecolumns.- by
A character vector describing the stratification of observations. This defaults to no grouping. This should be used when modelling multiple time series in order to identify them for downstream modelling
- copy
Should
obsbe copied (default) or modified in place?
Value
A data.table filtered so that each
reference_date is on or after the minimum
report_date in its group. Rows with NA
reference_date are kept.
See also
Preprocessing functions
enw_add_delay(),
enw_add_max_reported(),
enw_add_metaobs_features(),
enw_assign_group(),
enw_complete_dates(),
enw_construct_data(),
enw_extend_date(),
enw_filter_delay(),
enw_filter_reference_dates(),
enw_filter_report_dates(),
enw_flag_observed_observations(),
enw_impute_na_observations(),
enw_latest_data(),
enw_metadata(),
enw_metadata_delay(),
enw_missing_reference(),
enw_obs_at_delay(),
enw_preprocess_data(),
enw_reporting_triangle(),
enw_reporting_triangle_to_long(),
enw_retrospective()
Examples
library(data.table)
#>
#> Attaching package: ‘data.table’
#> The following object is masked from ‘package:base’:
#>
#> %notin%
obs <- data.table(
reference_date = as.IDate(c(
"2021-10-01", "2021-10-02", "2021-10-03"
)),
report_date = as.IDate(c(
"2021-10-02", "2021-10-02", "2021-10-03"
))
)
# The first row has reference_date before the minimum
# report_date, so it is removed
enw_filter_reference_dates_by_report_start(obs)
#> reference_date report_date
#> <IDat> <IDat>
#> 1: 2021-10-02 2021-10-02
#> 2: 2021-10-03 2021-10-03