View source: R/time_rows_per_date.R
| active_rows_by_date | R Documentation |
Match event dates, such as claim dates or inspection dates, to policy records that were active when the event occurred. The matched result contains the portfolio characteristics and coverage information applicable on each event date.
active_rows_by_date(
portfolio,
dates,
period_start,
period_end,
date,
by = NULL,
unmatched = c("drop", "keep"),
multiple_matches = c("all", "first", "last"),
nomatch = NULL,
mult = NULL
)
portfolio |
A |
dates |
A |
period_start |
Character string. Name of the portfolio column with period start dates. |
period_end |
Character string. Name of the portfolio column with period end dates. |
date |
Character string. Name of the date column in |
by |
Character vector with additional columns used to match |
unmatched |
Character string. Use |
multiple_matches |
Character string controlling events that match
multiple active portfolio rows. Use |
nomatch, mult |
Deprecated technical argument names. Use |
Claim and event files often contain an event date and policy identifier but
not the rating factors used at that point in time. The function performs an
interval match between those events and the portfolio history. Supplying a
policy identifier through by prevents an event from matching active periods
belonging to another policy.
This is a temporal matching operation rather than a portfolio reduction. See
merge_date_ranges() for consolidating connected coverage periods and
split_periods_to_months() for expanding periods into monthly records.
Multiple matches can be valid when one event relates to several concurrently
active coverages. They can also reveal overlapping or duplicated policy
periods. Use multiple_matches = "all" when every active record is relevant;
use "first" or "last" only when the source system defines which record
should take precedence.
With unmatched = "drop", events outside every applicable coverage period
are omitted. With unmatched = "keep", they remain visible with missing
portfolio fields. Retaining unmatched events is generally preferable during
data-quality review because it makes gaps in the policy history explicit.
The interval join is performed internally with data.table::foverlaps() on
local copies. Neither input is modified by reference. The output follows the
original order of dates and is always returned as a regular data.frame.
A regular data.frame containing the event records and the portfolio
information active on their dates. Event order is preserved. Depending on
multiple_matches, one event can produce more than one output row.
Martin Haringa
split_periods_to_months(), merge_date_ranges(), rating_grid()
portfolio <- data.frame(
policy_id = c("P001", "P001", "P002"),
coverage_start = as.Date(c("2024-01-01", "2025-01-01", "2025-01-01")),
coverage_end = as.Date(c("2024-12-31", "2025-12-31", "2025-12-31")),
sector = c("Retail", "Industry", "Services"),
insured_amount = c(500000, 750000, 300000),
earned_premium = c(900, 1250, 650)
)
claims <- data.frame(
claim_id = c("C001", "C002", "C003"),
policy_id = c("P001", "P001", "P002"),
claim_date = as.Date(c("2024-06-15", "2025-08-10", "2026-01-10")),
claim_amount = c(12000, 45000, 8000)
)
# Attach the policy characteristics that applied on each claim date.
active_rows_by_date(
portfolio,
claims,
period_start = "coverage_start",
period_end = "coverage_end",
date = "claim_date",
by = "policy_id"
)
# Keep claims outside the available policy history for data-quality review.
active_rows_by_date(
portfolio,
claims,
period_start = "coverage_start",
period_end = "coverage_end",
date = "claim_date",
by = "policy_id",
unmatched = "keep"
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.