View source: R/time_rows_per_date.R
| active_rows_by_date | R Documentation |
Matches event dates, such as claim dates or portfolio snapshot dates, to the rows that were active in the portfolio on those dates.
active_rows_by_date(
portfolio,
dates,
period_start,
period_end,
date,
by = NULL,
nomatch = NULL,
mult = "all"
)
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 |
nomatch |
When a row (with interval say, |
mult |
When multiple rows in y match to the row in x, |
This is useful when claim records or other dated events need the rating factors, premium, exposure, or policy attributes that were active at the event date. The function performs an interval join between event dates and portfolio coverage periods, optionally within matching identifiers such as a policy number.
An object with the same class as portfolio.
Martin Haringa
library(lubridate)
portfolio <- data.frame(
begin1 = ymd(c("2014-01-01", "2014-01-01")),
end = ymd(c("2014-03-14", "2014-05-10")),
termination = ymd(c("2014-03-14", "2014-05-10")),
exposure = c(0.2025, 0.3583),
premium = c(125, 150),
car_type = c("BMW", "TESLA"))
## Find active rows on different dates
dates0 <- data.frame(active_date = seq(ymd("2014-01-01"), ymd("2014-05-01"),
by = "months"))
active_rows_by_date(
portfolio,
dates0,
period_start = "begin1",
period_end = "end",
date = "active_date"
)
## With extra identifiers (merge claim date with time interval in portfolio)
claim_dates <- data.frame(claim_date = ymd("2014-01-01"),
car_type = c("BMW", "VOLVO"))
### Only rows are returned that can be matched
active_rows_by_date(
portfolio,
claim_dates,
period_start = "begin1",
period_end = "end",
date = "claim_date",
by = "car_type"
)
### When row cannot be matched, NA is returned for that row
active_rows_by_date(
portfolio,
claim_dates,
period_start = "begin1",
period_end = "end",
date = "claim_date",
by = "car_type",
nomatch = NA
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.