Description Usage Arguments Value Examples
Growth rate
1  | growth_rate(x, n = 12, annualize = 1, pct = TRUE, order_by = NULL)
 | 
x | 
 A numeric vector.  | 
n | 
 A positive integer indicating lag.  | 
annualize | 
 A positive integer indicating the number to annualize.  | 
pct | 
 A logical. If TRUE (default), returns percent growth rate.  | 
order_by | 
 A vector to order by.  | 
A numeric vector of the same length as 'x'.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16  | ## Not run: 
# example from base
growth_rate(1:10, 4)
growth_rate(1:10, 1, annualize = 4)
# Use order_by if data not already ordered (example from dplyr)
library(dplyr, warn.conflicts = FALSE)
tsbl <- tsibble(year = 2000:2005, value = (0:5)^2, index = year)
scrambled <- tsbl %>% slice(sample(nrow(tsbl)))
wrong <- mutate(scrambled, gr = growth_rate(value))
arrange(wrong, year)
right <- mutate(scrambled, gr = growth_rate(value, order_by = year))
arrange(right, year)
## End(Not run)
 | 
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.