Skip to contents

Sums the segments that share the values of the keep keys and drops the other keys: aggregate(tri, keep = "lob") sums states within each line, and the default keep = character() sums every segment into one. The result has the keep keys in the order given and its segments sorted by them. Cumulative values are summed cell by cell, and a cell is observed if any segment in the group observes it; an incremental triangle is summed as cumulative values and returned incremental. This is Python's Triangle.group_by(keys).

Arguments

x

A triangle.

keep

Names of the keys to keep; unknown or repeated keys are an error.

...

Unused.

Value

A triangle.

Details

The method is on stats::aggregate(), the generic this package already uses for the same operation on a predictive_distribution (also with keep), rather than group_by(), which would mask dplyr's lazy grouping verb of a different meaning.

See also

subset() to select segments by key value.

Examples

long <- data.frame(lob = c("auto", "auto", "home"), state = c("CA", "NY", "NY"),
                   year = 2020, age = 12, paid = c(1, 2, 3))
tri <- triangle(long, "year", "age", "paid", keys = c("lob", "state"))
aggregate(tri, keep = "lob")@index
#>    lob
#> 1 auto
#> 2 home
as.data.frame(aggregate(tri, keep = "lob"))
#>    lob     origin development paid
#> 1 auto 2020-01-01          12    3
#> 2 home 2020-01-01          12    3
aggregate(tri)@values[1, "paid", , ]
#> [1] 6