- 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);
My desired out put of 'Percentage_Change' column (additional column to dataset) would be like below. (Formula: 100/Previous Item row value * current row Item value...Example for 2nd row..100/1 * 5 = 500)
Row Percentage_Change
1 Skip
2 500
3 300
4 Skip
5 32.25806452
6 120
7 Skip
8 150
Thanks for all your help.