平均コスト「costmel」が の表が1つあり、その平均コストの下限の間にリスクスコア1-6の表が1つあります。スコア表を参照してテーブル列に値を追加する
aggProb_avCostMeld table:
costmel
1 19.39
2 0.00
3 4889.71
4 4612.82
5 0.00
6 3812.52
RisicoKostSchaal table:
Schaal low high
1 1 0 1.75e+02
2 2 175 3.50e+02
3 3 350 5.25e+02
4 4 525 7.00e+02
5 5 700 8.75e+02
6 6 875 1.00e+08
私は何をしたいことは、各I aggProb_avCostMeldの$ costmel用で、 チェックはそれがRisicoKostSchaal高い低域のyの範囲内にあるとRisicoKostSchaal $ Schaalの対応数を返し、新しい列」のことを置く場合aggProb_avCostMeldテーブルの「costrisk」
for(i in aggProb_avCostMeld$costmel) {
for (y in RisicoKostSchaal){
if(aggProb_avCostMeld$costmel[i] >= RisicoKostSchaal$low[y] & aggProb_avCostMeld$costmel[i] < RisicoKostSchaal$high[y]){
aggProb_avCostMeld$costrisk[i] <- RisicoKostSchaal$Schaal[y]
}
}
}
しかし、それは動作しませんでした:私が試した
コードがあります。
dput(aggProb_avCostMeld)
c(19.3984518231819, 0, 4889.71644908616, 4612.82921161826, 0,
3812.52550091075, 0, 0, 0, 1484.24951267057, 0, 789.423206278027,
2529.65298303229, 3600.89832689833)
dput(RisicoKostSchaal)
structure(list(Schaal = c(1, 2, 3, 4, 5, 6), low = c(0, 175,
350, 525, 700, 875), high = c(175, 350, 525, 700, 875, 1e+08)), .Names = c("Schaal",
"low", "high"), row.names = c(NA, -6L), class = "data.frame")
' dput(aggProb_avCostMeld)の結果を追加してください 'と' dput(RisicoKostSchaal)、/貼り付けをコピーすることが容易になります。 – Tensibai
期待される出力は何ですか? – mtoto
'RisicoKostSchaal $ Schaalのようなものです。 – Sotos