| prc_change | R Documentation |
Calculates the percentage change in a time series from the initial value. The time series is defined by
y the response variable, indexed by x, the time variable. The per argument can optionally be used
to scale the result according to a period of time. E.g. if the units of x are years, setting x = 10
will measure the percentage change per decade.
prc_change(y, x, per = 1)
y |
A numeric vector |
x |
A numeric vector of the same length as |
per |
Numeric value to scale the change according to a period of time. See description. |
This function operates in two ways, depending on the number of data points. If x and y have two non-NA
observations, percentage change is calculated using the first and last values. If three or more points are
available, a linear regression is used to estimate the average percentage change. If fewer than two points
are available, the percentage change cannot be estimated and NA is returned.
If all y values are equal, it will return a change of zero.
Percentage change as a scalar value.
# a time vector
x <- 2011:2020
# some random points
y <- runif(10)
# find percentage change per decade
prc_change(y, x, 10)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.