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 %>%
group_by(year) %>%
mutate(diff_earnings_average = year - lag(year),
diff_aveearnings_growth = realawe - lag(realawe),
rate_percent_average = (diff_aveearnings_growth/diff_earnings_average)/realawe*100)
Error in /.difftime(diff_aveearnings_growth,diff_earninigs_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?
This is the dput output:
structure(list(year = structure(c(946684800, 949363200, 951868800,
954547200), class = c("POSIXct", "POSIXt"), tzone = "UTC"), realawe = c(421.168268440558,
410.160453374782, 422.012733947076, 423.306583956499), diff_aveearnings_growth = c(NA,
-11.0078150657755, 11.8522805722941, 1.29385000942239), rate_percent_average = c(NA,
-2.68378264535347, 2.80851254450074, 0.305653173954731)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -4L))