Calculate A Moving Average

Want to learn more? I recommend working through: R for Data Science, R Cookbook, and R Graphics Cookbook.

original source:

# create some simulated data
x <- 1:10
Warning message:
: package ‘forecast’ was built under R version 3.1.3Loading required package: zoo

Attaching package: ‘zoo’

The following objects are masked from ‘package:base’:

    as.Date, as.Date.numeric

Loading required package: timeDate
This is forecast 5.9
ma(x, order = 5, centre=TRUE)
 [1] NA NA  3  4  5  6  7  8 NA NA