psych (version 1.0-95)

harmonic.mean: Find the harmonic mean of a vector, matrix, or columns of a data.frame

Description

The harmonic mean is merely the reciprocal of the arithmetic mean of the reciprocals.

Usage

harmonic.mean(x,na.rm=TRUE)

Arguments

x
a vector, matrix, or data.frame
na.rm
na.rm=TRUE remove NA values before processing

Value

  • The harmonic mean(s)

Details

Included as an example for teaching about functions. As well as for a discussion of how to estimate central tendencies.

Examples

Run this code
x <- seq(1,5)
x2 <- x^2
x2[2] <- NA
X <- data.frame(x,x2)
harmonic.mean(x)
harmonic.mean(x2)
harmonic.mean(X)
harmonic.mean(X,FALSE)

Run the code above in your browser using DataCamp Workspace