I am trying to calculate the month difference between year month dates. For example in the dataframe I have the following year/months and I would like to calculate the following results:-
Year/Month Result 201910 N/a 201912 2 202001 1 202010 9
So it calculates the difference from the current row Year/Month from the previous row.So I was thinking something like df$result <- df$Year/Month-lag(df$Year/Month)
However, this won't work for 202001-201912. I know there is a function DATEDIF in excel which works if you have full dates ie. 01/12/2019 - 01/01/2020 =DATEDIF(A1,A2,"M"). I am hoping I can find a solution in r. Any information that may point me in the right direction would be appreciated. I appreciate, I might be being a bit vague but I am relatively new to this.
Cheers,
Forrestgump1980