View, summarise and print a triangle
triangle_views.Rdas.matrix() gives one segment and measure of a triangle as an
origin x development matrix: origin labels as row names, ages in months
as column names, NA where a cell is not observed. Key arguments choose
the segment, one value each (compared as character); keys not named may
take any value, but the choice must leave one segment, so a triangle
with one segment needs none. column names the measure and may be left
out when there is only one. This is Python's
Triangle.view(column=None, **keys).
Arguments
- x, object
A triangle.
- column
Name of the measure, or
NULLfor the only one.- max_rows, max_cols
Rows and development ages shown before the middle ones are left out; 0 for no limit.
- ...
For
as.matrix(), key conditions askey = value; unused otherwise.
Value
as.matrix(): a numeric matrix. summary(): a data.frame.
format(): a character vector of lines. print(): x, invisibly.
Details
summary() gives one row per segment and measure: the key columns,
column, n_origins (origins with an observed value), first_origin
and last_origin of those, valuation (the last day of the latest
valuation with an observed value), latest (the sum over origins of the
latest cumulative value, so for an incremental triangle the sum of every
increment) and cumulative. Origins and valuation are NA for a
segment with no observed value of the measure.
print() and format() show the grid of as.matrix() for a triangle
with one segment and one measure, and the summary() table otherwise,
with numbers rounded for reading; long tables show their first and last
rows around a .... Python prints the same text.
as.matrix() is a method on base R's generic rather than a new view()
verb, which would mask tibble::view() once the tidyverse is attached.
A key named x or column cannot be chosen this way; use
subset() first.
Errors: an unknown key, value or column, a choice that matches several
segments, a missing column with several measures, or a key with the
name of a summary column.
Examples
long <- data.frame(lob = rep(c("auto", "home"), each = 3), year = c(2020, 2020, 2021),
age = c(12, 24, 12), paid = c(100, 150, 110, 40, 60, 45))
tri <- triangle(long, "year", "age", "paid", keys = "lob")
tri
#> Triangle: 2 segments x 1 column, keys lob (cumulative, valuation 2021-12)
#> lob column n_origins first_origin last_origin valuation latest
#> auto paid 2 2020 2021 2021-12 260
#> home paid 2 2020 2021 2021-12 105
as.matrix(tri, lob = "auto")
#> development
#> origin 12 24
#> 2020 100 150
#> 2021 110 NA
summary(tri)
#> lob column n_origins first_origin last_origin valuation latest cumulative
#> 1 auto paid 2 2020 2021 2021-12-31 260 TRUE
#> 2 home paid 2 2020 2021 2021-12-31 105 TRUE
subset(tri, lob = "home")
#> Triangle: paid, lob=home (cumulative, valuation 2021-12)
#> 12 24
#> 2020 40 60
#> 2021 45