Compute Harmonic Mean of Vector in R
In this article, we will see how to find the harmonic mean of the vector in R Programming Language.
The harmonic mean is used when an average of rates is required, below is the formula.
Harmonic mean of n numbers x1, x2, x3, . . ., xn can written as below.
Harmonic mean = n / ((1/x1) + (1/x2) + (1/x3) + . . . + (1/xn))
In R, we can compute the harmonic mean by using harmonic.mean() function.
where, vector is an input vector.
But this method is available in psych package. so we have to install and import it.
Install - install.packages("psych") Import - library("psych")
In this example, we are going to find the harmonic mean of a vector with 4 elements.
In this example, we are going to find the harmonic mean of a vector with 10 elements.