Skip to content

Instantly share code, notes, and snippets.

@fredrick

fredrick/powermean.r

Last active Dec 16, 2015
Embed
What would you like to do?
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
You can’t perform that action at this time.