Skip to content

Instantly share code, notes, and snippets.

@UniIsland
Created February 10, 2018 16:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save UniIsland/3ca40a9b2ee842bfd876a0e6354058f0 to your computer and use it in GitHub Desktop.
Save UniIsland/3ca40a9b2ee842bfd876a0e6354058f0 to your computer and use it in GitHub Desktop.
Calculate Moving Average with R
## calculating moving average
## x: data vector
## n: use how many samples
## s: 1 - with lag; 2 - symmetrically
f.ma <- function(x,n=5,s=2){filter(x,rep(1/n,n), sides=s)}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment