Description Usage Arguments Details Value Examples
Calculate the percentage change from a specified lag, including within groups
1 | PercChange(data, Var, GroupVar, NewVar, slideBy = -1, type = "percent", ...)
|
data |
a data frame object. |
Var |
a character string naming the variable you would like to find the percentage change for. |
GroupVar |
a character string naming the variable grouping the units
within which the percentage change will be found for (i.e. countries in a
time series). If |
NewVar |
a character string specifying the name for the new variable to place the percentage change in. |
slideBy |
numeric value specifying how many rows (time units) to make the percentage change comparison for. Positive values shift the data up–lead the data. |
type |
character string set at either |
... |
arguments passed to |
Finds the percentage or proportion change for over a given time period either within groups of data or the whole data frame. Important: the data must be in time order and, if groups are used, group-time order.
a data frame
1 2 3 4 5 6 7 8 9 10 11 12 | # Create fake data frame
A <- c(1, 1, 1, 1, 1, 2, 2, 2, 2, 2)
B <- c(1:10)
Data <- data.frame(A, B)
# Find percentage change from two periods before
Out <- PercChange(Data, Var = 'B',
type = 'proportion',
NewVar = 'PercentChange',
slideBy = -2)
Out
|
Remember to put data in time order before running.
Lagging B by 2 time units.
Warning message:
PercChange is depricated. Please use change.
A B PercentChange
1 1 1 NA
2 1 2 NA
3 1 3 2.0000000
4 1 4 1.0000000
5 1 5 0.6666667
6 2 6 0.5000000
7 2 7 0.4000000
8 2 8 0.3333333
9 2 9 0.2857143
10 2 10 0.2500000
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.