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

1 Answer

0 votes
by (33.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

...