how to use the growth function with one column in date format

Hi,
I am using a dataset to calculate the growth in earnings from 2000-2019 and have the earnings for every month within those years. It is in the ymd format, eg 2000-01-01

I am trying to calculate the growth rate between each month but it won't let me use the lag function properly due to the year column being in date format as above.

Code is:
average_weekly_earnings <- average_weekly_earnings %>%
mutate(diff_earnings_average = year - lag(year),
diff_aveearnings_growth = realawe - lag(realawe),

    Error in' /.difftime'(diff_aveearnings_growth, diff_earnings_average) : 
    second argument of / cannot be a "difftime" object

This code appears when I try to run it.

Does anyone known how to fix this?

I don't understand why you need to apply lag() to the year variable. Just applying it to the variable containing earnings should be sufficient. Can you show us what your data looks like?

Please be aware of the site's cross-posting policy:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.