function to calculate moving average

Moving_average(x, periods = 5, NA_RM = TRUE)

Arguments

x

A data frame contain the variable for calculation

periods

An odd number of the periods in MA. The default is 5, i.e., 2 lags and 2 leads

NA_RM

If TRUE, remove NA in calculating mean, otherwise returning NA

Value

A data frame