# Mean Functions

The package provides functions to compute means of different kinds.

`StatsBase.geomean`

— Function`geomean(a)`

Return the geometric mean of a collection.

`StatsBase.harmmean`

— Function`harmmean(a)`

Return the harmonic mean of a collection.

`StatsBase.genmean`

— Function`genmean(a, p)`

Return the generalized/power mean with exponent `p`

of a real-valued array, i.e. $\left( \frac{1}{n} \sum_{i=1}^n a_i^p \right)^{\frac{1}{p}}$, where `n = length(a)`

. It is taken to be the geometric mean when `p == 0`

.

The `mean`

and `mean!`

functions are also extended to accept a weight vector of type `AbstractWeights`

to compute weighted mean.

`Statistics.mean`

— Function`mean(A::AbstractArray, w::AbstractWeights[, dims::Int])`

Compute the weighted mean of array `A`

with weight vector `w`

(of type `AbstractWeights`

). If `dim`

is provided, compute the weighted mean along dimension `dims`

.

**Examples**

```
w = rand(n)
mean(x, weights(w))
```

`Statistics.mean!`

— Function`mean!(R::AbstractArray, A::AbstractArray, w::AbstractWeights[; dims=nothing])`

Compute the weighted mean of array `A`

with weight vector `w`

(of type `AbstractWeights`

) along dimension `dims`

, and write results to `R`

.