Select segments and columns of a triangle by name
subset.triangle.RdKeeps the segments whose key values match and the measure columns named:
subset(tri, lob = "auto", state = c("CA", "NY"), columns = "paid").
Each key argument gives the values to keep (compared as character, as
keys are stored); segments must match every key argument and keep their
order. Columns are kept in the order given. This is Python's
Triangle.select(columns=None, **keys).
Arguments
- x
A triangle.
- ...
Key conditions as
key = values.- columns
Column names to keep, in order, or
NULLfor all.
Value
A triangle.
Details
The method is on base R's subset() generic rather than a new verb, so
it does not mask dplyr::filter() or dplyr::select(). A key named x
or columns cannot be selected this way.
Errors: a key, value or column that does not exist or is given twice, an empty set of values, an unnamed argument, or a selection that matches no segment.
See also
aggregate() to sum segments over keys.
Examples
long <- data.frame(lob = rep(c("auto", "home"), each = 3), year = c(2020, 2020, 2021),
age = c(12, 24, 12), paid = 1:6, incurred = 2 * (1:6))
tri <- triangle(long, "year", "age", c("paid", "incurred"), keys = "lob")
subset(tri, lob = "home", columns = "incurred")@values
#> , , origin = 2020, development = 12
#>
#> column
#> index incurred
#> home 8
#>
#> , , origin = 2021, development = 12
#>
#> column
#> index incurred
#> home 12
#>
#> , , origin = 2020, development = 24
#>
#> column
#> index incurred
#> home 10
#>
#> , , origin = 2021, development = 24
#>
#> column
#> index incurred
#> home NA
#>
subset(tri, columns = c("incurred", "paid"))@columns
#> [1] "incurred" "paid"