Description Usage Arguments Details Value See Also Examples
Create a moving average for a period before or after each time point for a given variable
1 2 |
data |
a data frame object. |
Var |
a character string naming the variable you would like to create the lag/lead moving averages from. |
GroupVar |
a character string naming the variable grouping the units
within which |
periodBound |
integer. The time point for the outer bound of the time
period over which to create the moving averages. The default is |
offset |
integer. How many time increments away from a given time point
to begin the moving average time period. The default is |
NewVar |
a character string specifying the name for the new variable to place the slid data in. |
reminder |
logical. Whether or not to remind you to order your data by
the |
slideMA
is designed to give you more control over the window
for creating the moving average. Think of the periodBound
and
offset
arguments working together. If for example,
periodBound = -3
and offset = 1
then the variable of interest
will be lagged by 2 then a moving average window of three time increments
around the lagged variable is found.
a data frame
1 2 3 4 5 6 7 8 9 10 11 12 | # Create dummy data
A <- B <- C <- sample(1:20, size = 20, replace = TRUE)
ID <- sort(rep(seq(1:4), 5))
Data <- data.frame(ID, A, B, C)
# Lead the variable by two time units
DataSlidMA1 <- slideMA(Data, Var = 'A', NewVar = 'ALead_MA',
periodBound = 3)
# Lag the variable one time unit by ID group
DataSlidMA2 <- slideMA(data = Data, Var = 'B', GroupVar = 'ID',
NewVar = 'BLag_MA', periodBound = -3, offset = 2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.