Description Usage Arguments Details Value Examples

We created a function that calculates a moving average of a specified window width across a vector.

1 | ```
movingaverage(x = x, side = "both", numbertoside = NULL)
``` |

`x` |
a vector for which you will be calculating the moving average. |

`side` |
whether you want to average elements on the left, right, or both sides; should accept the following values: “left”,“right”,“both”. |

`numbertoside` |
the number of elements to the side of your index element that you want to include in the moving average. |

To create this function, we only used methods that were introduced in either Lecture 1 or Lecture 2.

A vector of the moving average

`Input` |
input vector |

`Output` |
output vector |

1 2 3 | ```
inputdata<-c(0,2.457,3.878,3.663,1.90,-0.658,-2.943,-3.986,-3.349,-1.299,
1.299,3.349,3.986,2.943,0.658,-1.904,-3.663,-3.878,-2.457,0)
movingaverage(x=inputdata,numbertoside=3,side="left")
``` |

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.