harmonic.mean.Rd
The harmonic mean is merely the reciprocal of the arithmetic mean of the reciprocals.
harmonic.mean(x,na.rm=TRUE,zero=TRUE)
Included as an example for teaching about functions. As well as for a discussion of how to estimate central tendencies.
Also used in statsBy
to weight by the harmonic mean.
Values of 0 can be included (in which case the harmonic.mean = 0) or converted to NA according to the zero option.
Added the zero option, March, 2017.
The harmonic mean(s)
Included as a simple demonstration of how to write a function
x <- seq(1,5)
x2 <- x^2
x2[2] <- NA
y <- x - 1
X <- data.frame(x,x2,y)
harmonic.mean(x)
#> [1] 2.189781
harmonic.mean(x2)
#> [1] 3.295949
harmonic.mean(X)
#> x x2 y
#> 2.189781 3.295949 0.000000
harmonic.mean(X,na.rm=FALSE)
#> x x2 y
#> 2.189781 NA 0.000000
harmonic.mean(X,zero=FALSE)
#> x x2 y
#> 2.189781 3.295949 1.920000