movingaverage: Moving Average

Description Usage Arguments Details Value Examples

View source: R/Class 9 R Script.R

Description

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

Usage

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

Arguments

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.

Details

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

Value

A vector of the moving average

Input

input vector

Output

output vector

Examples

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")

alvancheng/ExamplePackage documentation built on March 18, 2018, 6:45 p.m.