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"
)
Run the code above in your browser using DataLab