我有以下數據框:數據框有1000多行,我需要使用最後3列更新列P1-P9。R:如何計算計算字段列中的值R
P1 P2 P3 P4 P5 P6 P7 P8 P9 Noofmonths divamount beginingMonth
0 0 0 0 0 0 0 0 0 3 29948.333 4
0 0 0 0 0 0 0 0 0 3 29766.667 4
0 0 0 0 0 0 0 0 0 3 1778.667 4
0 0 0 0 0 0 0 0 0 2 2595.6 3
條件:
if beginingMonth = 4 then select Noofmonths.
if Noofmonths= 3 then P4 = divamount, P5 = divamount, p6 = divamount
if beginingMonth = 1 then select Noofmonths.
if Noofmonths= 1 then P1 = divamount
if beginingMonth = 2 then select Noofmonths.
if Noofmonths= 2 then P2 = divamount, P3 = divamount.
這樣的問題已經有很多次被問及(並回答過)了。用搜索引擎搜索「R數據幀條件替換」。 – tagoma
看看可以嵌套的'ifelse'。回報任何問題。 – Parfait