| slideMA {DataCombine} | R Documentation | 
Create a moving average for a period before or after each time point for a given variable
Description
Create a moving average for a period before or after each time point for a given variable
Usage
slideMA(data, Var, GroupVar, periodBound = -3, offset = 1, NewVar,
  reminder = TRUE)
Arguments
| 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  | 
Details
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.
Value
a data frame
See Also
Examples
 # 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)