RのChainLadder損失三角形の列をスライスしようとしています。
選択/フィルター機能を使用してみましたが、これらのエラーが発生しました。
Error in UseMethod("select_") : no applicable method for 'select_' applied to an object of class "c('triangle', 'matrix')"
Error in UseMethod("filter_") : no applicable method for 'filter_' applied to an object of class "c('triangle', 'matrix')"
サンプルコードは次のとおりです。
# ChainLadder package is required.
library(ChainLadder)
df <- data.frame(Month = c("2019-10-01", "2019-10-01", "2019-10-01", "2019-10-01",
"2019-11-01", "2019-11-01", "2019-11-01",
"2019-12-01", "2019-12-01",
"2020-01-01"),
T = c(1, 2, 3, 4, 1, 2, 3, 1, 2, 1),
value = c(100, 160, 220, 250, 100, 200, 250, 120, 150, 110))
df_Triangle <- as.triangle(df,
origin = "Month",
dev = "T",
value = "value")
df_Triangle
## The code below won't work on a triangle.
# df_Triangle %>% select(Month, 1, 2)
# df_Triangle %>% filter(T %in% c(1,2))
私の三角形の出力:
私の欲望の出力:
ありがとうございました。
ChainLadder
パッケージに必要なデータ構造についてはまったく詳しくありませんが、試行錯誤のアプローチから、フィールドで三角形と呼ばれるものが実際にはRの行列であることがわかります。次に、次のdplyr
ような動詞を使用しようとしています。select
そしてfilter
、失敗するマトリックス上で-彼らはデータフレームを期待しています。
しかし、Rでは行列のインデックス付けは簡単です。これを試しましたか?:
# Select matrix columns 1 and 2
df_Triangle[, 1:2]
または
# create a vector of column indices you want to use for selection/filtering.
# It seems that the column names of the triangle are the values of T
t_index <- colnames(df_Triangle) %in% c("1", "2")
# apply the vector of indices
df_Triangle[, t_index]
# T
# Month 1 2
# 2019-10-01 100 160
# 2019-11-01 100 200
# 2019-12-01 120 150
# 2020-01-01 110 NA
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加