Calculates the rate of change of a value, provided a time variable.
time
and units
should be compatible with the lubridate
package
get_rate(x, time, unit = "days", historic = "backward")
x | value to calculate the rate of |
---|---|
time | date or time variable to be used in the calculations of rate |
unit | units of time to be used in output |
historic | accepts |
x <- c(4, 2, 1, 4, 6, 7, 4, 2, 2, 9) time <- lubridate::ymd(c( "2000-08-23", "2000-04-19", "2000-10-12", "2000-07-22", "2000-12-13", "2000-06-20", "2000-01-02", "2000-11-12", "2000-03-11", "2000-08-04" )) get_rate(x, time)#> [1] -0.26315789 0.00000000 -0.06000000 -0.09375000 0.12903226 0.08064516 #> [7] NA 0.03225806 -0.02898551 0.38461538