【发布时间】:2017-07-10 17:24:07
【问题描述】:
我有以下数据框:数据框有超过 1000 行,我需要使用最后 3 列更新列 P1-P9。
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 dataframe 条件替换”。
-
查看可以嵌套的
ifelse。报告任何问题。
标签: r loops with-statement