+5 votes
in Programming Languages by (34.9k points)
What R function should I use to compute the harmonic mean of a vector of numbers?

1 Answer

+1 vote
by (157k points)
selected by
Best answer

You can use the harmonic.mean() function of the psych library to calculate the harmonic mean. If the package psych is not installed, you can install it by running command install.packages("psych").

> library(psych)
> x <- seq(1,5)
> x
[1] 1 2 3 4 5
> harmonic.mean(x)
[1] 2.189781

Related questions