mean2: Calculation of mean (extended)

Description Usage Arguments Details Value Author(s) References See Also Examples

Description

Calculating the arithmetic mean, weighted or non-weighted, or the geometric mean

Usage

1
mean2(x, weighting = NULL, output = "mean", na.rm = TRUE)

Arguments

x

a numeric vector

weighting

a numeric vector containing weighting data to compute the weighted arithmetic mean (instead of the non-weighted)

output

argument to specify the output (output = "mean" returns the arithmetic mean, output = "geom" returns the geometric mean)

na.rm

logical argument that whether NA values should be extracted or not

Details

This function uses the formula for the weighted arithmetic mean from Sheret (1984).

Value

Single numeric value. If output = "mean" and weighting is specified, the function returns a weighted arithmetic mean. If output = "geom", the geometric mean is returned.

Author(s)

Thomas Wieland

References

Bahrenberg, G./Giese, E./Mevenkamp, N./Nipper, J. (2010): “Statistische Methoden in der Geographie. Band 1: Univariate und bivariate Statistik”. Stuttgart: Borntraeger.

Sheret, M. (1984): “The Coefficient of Variation: Weighting Considerations”. In: Social Indicators Research, 15, 3, p. 289-295.

See Also

sd2

Examples

1
2
3
4
5
6
avector <- c(5, 17, 84, 55, 39)
mean(avector)
mean2(avector)
wvector <- c(9, 757, 44, 18, 682)
mean2 (avector, weighting = wvector)
mean2 (avector, output = "geom")

Example output

[1] 40
[1] 40
[1] 29.2702
[1] 27.35427

REAT documentation built on Sept. 5, 2021, 5:18 p.m.