Description Usage Arguments Notice See Also Examples
Harmonic, geometric, quadratic, cubic, power and Lehmer means.
1 2 3 4 5 6 7 8 9 10 11 |
x |
numeric vector of values whose *mean is to be computed |
na.rm |
logical; should |
zero.rule |
for the geometric mean, how should zeros be dealt with? Add
one before, and subtract one after the calculation (see |
p |
exponential power. For the power mean |
For some of these means zeros and/or negative values are undefined, or make otherwise little sense in context. Workarounds are given for the geometric mean, but if you end up using it on data ≤ 0, the wise call would be to reconsider whether using a geometric mean really makes sense in that case.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | funl <- substitute(c(harm, geom, mean, quad, cubi))
xl <- list(c( 1, 2, 3, 5),
c(-1, 1, 2, 3, 5),
c( 0, 1, 2, 3, 5),
c(-1, 0, 1, 2, 3, 5))
m <- sapply(xl, function(x) sapply(eval(funl), function(f) f(x)))
rownames(m) <- as.character(funl)[-1]
colnames(m) <- c("posi", "1neg", "zero", "1ngz")
round(m, 3)
harm(xl[[1]]); powr(xl[[1]], -1); lehm(xl[[1]], 0)
y <- c(0, 1, 5, 0, 6, 5, 9)
geom(y, zero.rule="1p")
geom(y, zero.rule="rm")
geom(y, zero.rule="1")
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.