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

1 Answer

+1 vote
by (48.7k points)

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


...