a_genmean | R Documentation |
Weighted generalised mean of a vector. NA
are skipped by default.
a_genmean(x, w = NULL, p)
x |
A numeric vector of positive values. |
w |
A vector of weights, which should have length equal to |
p |
Coefficient - see details. |
The generalised mean is as follows:
y = \left( \frac{1}{\sum w_i} \sum w_i x_i^p \right)^{1/p}
where p
is a coefficient specified in the function argument here. Note that:
For negative p
, all x
values must be positive
Setting p = 0
will result in an error due to the negative exponent. This case
is equivalent to the geometric mean in the limit, so use a_gmean()
instead.
Weighted harmonic mean, as a numeric value.
# a vector of values
x <- 1:10
# a vector of weights
w <- runif(10)
# cubic mean
a_genmean(x,w, p = 2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.