I have a dataframe with two rows of data. I would like to add a third row with values representing the difference between the previous two.
The data is in the following format:
Month A B C D E F
Jan 1 2 4 8 4 1
Feb 1 1 4 5 2 0
I would like to add an extra row with a calculation to give the change across the two months:
Month A B C D E F
Jan 1 2 4 8 4 1
Feb 1 1 4 5 2 0
Change 0 1 0 3 2 1
I've been looking at various functions to add additional rows including rbind
and mutate
but I'm struggling to perform the calculation in the newly created row.
manymodelr::rowdiff(df[,-1])[1,]
. – NelsonGonMonth
column the 1st one? Can you check output ofdf[1, -1] - df[2, -1]
? Does it give you right numbers? – Ronak ShahMonth = "Change"
argument - r didn't like have date and text values in the same column – Ant