我有以下数据框:数据框有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