R/growth.R

Defines functions growth

Documented in growth

#' Calculate Decimal Growth Rate.
#' 
#' \code{growth} return the decimal growth rate of a numeric vector. It employs data.table:::shift() to achieve the best performance.
#'
#' @export
#' @param x A numeric vector.
#' @return The decimal growth rate of vector \code{x}. The first element will be NA.
#' @examples
#' growth(c(1, 2, 1))

growth <- function(x) {
    x / shift(x) -1
}
XiaomoWu/utilr documentation built on July 30, 2022, 11:26 a.m.