Description Usage Arguments Details Value Note Author(s) References See Also Examples
Calculates proportion/percent changes between subsequent (or lagged) elements of a numeric vector.
1 |
x |
Numeric vector. |
lag |
Controls spacing between proportion/percent changes. For example, lag of 1 means you want to calculate changes between elements 1 and 2, 2 and 3, 3 and 4, and so on; a lag of 2 means you want calculate changes between elements 1 and 3, 2 and 4, 3 and 5, and so on. |
percent |
|
Each proportion/percent change is based on two numbers, say x1
and
x2
. The proportion change is defined as (x1 - x2) / x1
, and the
percent change is the same quantity multiplied by 100
. Notice that this
is NOT proportion/percent difference, which divides by the average of x1
and x2
rather than the initial value x1
. See pdiffs
for the proportion/percent difference operation.
Numeric vector.
This function uses C++ code to achieve an approximate 2 times speed increase
compared to the base R code:
len <- length(x); p1 <- x[2: len]; p2 <- x[1: (len - 1)]; p2 / p1 - 1
.
Dane R. Van Domelen
Acknowledgment: This material is based upon work supported by the National Science Foundation Graduate Research Fellowship under Grant No. DGE-0940903.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.