Skip to content

Instantly share code, notes, and snippets.

@fredrick
Last active December 16, 2015 07:48
Show Gist options
  • Save fredrick/5400923 to your computer and use it in GitHub Desktop.
Save fredrick/5400923 to your computer and use it in GitHub Desktop.
Generalized/power mean with R
# Power mean
## Examples:
## p = 1, arithmetic mean
## p = 2, quadratic mean (RMS)
pmean <- function(x, p) {
library(TTR)
return(tail(TTR::SMA(x^p, length(x))^(1/p), n=1))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment