- I like to compute 'Percentage of change between two rows' while Item changes in rows.
For first row of items, I am ok to place some text or blank (example ‘skip’ or blank is ok) because of no comparison of previous row for same item
df <- data.frame(period=rep(1:4,2), farm=c(rep('A',4),rep('B',4)), cumVol=c(1,5,15,31,10,12,16,24), item=c(rep('Z',3),rep('Y',3),rep('X',2)), other = 1:8);
我希望在数据集上添加一个名为“Percentage_Change”的附加列,并且该列的输出结果如下所示。(公式:100/前一项行值*当前行项值...例如对于第二行..100/1 * 5 = 500)
Row Percentage_Change
1 Skip
2 500
3 300
4 Skip
5 32.25806452
6 120
7 Skip
8 150
感谢您的所有帮助。