I have a dataframe DF, with two columns A and B shown below:
A B 1 0 3
The R library TTR has a number of functions for calculating averages over sliding windows
SMA = simple moving average
data$sma <- SMA(data$B, 3)
More documentation is here http://cran.r-project.org/web/packages/TTR/TTR.pdf