This function returns a (by default) seven-day moving average of the variable passed in. Make sure the data is pre-sorted by date, and grouped by the appropriate grouping. The data should have no gaps in time.
ma(x, n = 7)
The variable to calculate the moving average of.
The number of lags to cover in the moving average.
ma(1:9) #>  NA NA NA NA NA NA 4 5 6