Learn R Programming

REAT (version 3.0.3)

mean2: Calculation of mean (extended)

Description

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

Usage

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

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.

Details

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

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

Run this code
# NOT RUN {
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")
# }

Run the code above in your browser using DataLab