as.triangle生成长表而不是三角形

时间:2020-04-14 09:00:32

标签: r

我是R语言编程的新手,但是有其他语言的经验。我正在尝试使用ChainLadder包中的as.triangle创建一个精算三角形,但它是以长表而不是三角形的形式出现的。

我的代码如下:

 leo_step2 <- structure(list(DEVELOPMENTDATE = structure(c(18331, 18331, 18338, 18338, 18338, 18345, 18345, 18345, 18345, 18352, 18352, 18352, 18352), class = "Date"), 
               EFFYEAR = c(2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020, 2020), 
               EFFMNTH = c("03", "03", "03", "03", "03", "03", "03", "03", "03", "03", "03", "03", "03"), 
               DevWeek = c(1, 3, 1, 2, 3, 1, 2, 3, 4, 1, 2, 4, 5), 
               sales = c(4, 6, 11, 5, 4, 19, 2, 1, 3, 9, 4, 2, 4), 
               premium = c(777, 7000, 1221, 1360, 300, 7000, 500, 100, 550, 7000, 3000, 1100, 1200)), 
          class = c("grouped_df", "tbl_df", "tbl", "data.frame"), row.names = c(NA, -13L), 
          groups = structure(list( DEVELOPMENTDATE = structure(c(18331, 18338, 18345, 18352), class = "Date"), 
                                   EFFYEAR = c(2020, 2020, 2020, 2020), EFFMNTH = c("03", "03", "03", "03"), 
                                   .rows = list(1:2, 3:5, 6:9, 10:13)), row.names = c(NA, -4L), 
                             class = c("tbl_df", "tbl", "data.frame"), .drop = TRUE)) 


leo_march <- subset(leo_step2, EFFYEAR=='2020' & EFFMNTH=='03')

leo_tri_incr <- as.triangle(leo_march, origin="DEVELOPMENTDATE", dev="DevWeek", "sales", na.rm=FALSE)

leo_tri_cum <- incr2cum(leo_tri_incr)

leo_tri_cum

#                DevWeek
# DEVELOPMENTDATE  1  2  3  4  5
#      2020-03-10  4 NA NA NA NA
#      2020-03-17 11 16 20 NA NA
#      2020-03-24 19 21 22 25 NA
#      2020-03-31  9 13 NA NA NA

它显示的数字是正确的,但是它没有格式化为三角形。有人可以帮忙吗?

0 个答案:

没有答案