
Filter a long-format table to recent calendar diagonals
Source:R/utils.R
dot-apply_recent_filter.RdReturns a subset of the input data.table containing only rows whose
calendar position falls within the last recent calendar diagonals of
its group.
The group-wise long-form condition is
rank(cohort) + dev - 1 > max(rank(cohort) + dev - 1) - recent.
Usage
.apply_recent_filter(
dt,
recent,
groups = character(0),
cohort,
dev,
dev_split = NULL
)Arguments
- dt
A long-format development
data.table.- recent
Positive integer or
NULL. WhenNULLor missing,dtis returned unchanged.- groups
Character vector of group columns (may be empty).
- cohort
Single column name for the cohort variable (e.g.
cohort).- dev
Single column name for the development variable (e.g.
devforTriangleobjects, orata_fromforATA/EDobjects).- dev_split
Optional SA-boundary specifier. Accepts:
NULL– no SA boundary; the recent wedge applies to every row.A single non-NA numeric scalar – the maturity target dev (=
ata_to, the first CL-region dev). The recent filter is applied only to rows wheredev >= dev_split(CL region); rows withdev < dev_split(ED region) are kept unconditionally.A
data.table[groups..., dev_split]– per-group SA boundary (differentk*per group). The group columns must be a subset ofgroups. Each row ofdtlooks up itsdev_splitvia left-join; rows whose group has no matching entry (NA after the join) are treated as ifdev_split = NULLfor that row (recent wedge applies to all dev for them).