Harmonic Mean in R (Harmonic mean of column in R)

Harmonic mean of the column in R is calculated using harmonic.mean() function of the psych package. Let’s see how to calculate the harmonic mean of the dataframe in R and harmonic mean of the vector with an example of each.

Let’s first create the dataframe


df1 = data.frame(Name = c('George','Andrea', 'Micheal','Maggie','Ravi','Xien','Jalpa'), 

So the resultant dataframe will be

Harmonic Mean in R 1 harmonic mean of column in R 1


Harmonic mean of the column in R:

Harmonic mean of the Mathematics_score is calculated as shown below


So the Harmonic mean of the column will be

[1] 59.09441


Harmonic mean of the vector in R:

vector1 <- c(50,47,45,89,66,49,72)  # create vector

So the Harmonic mean of the vector will be,

[1] 56.36827




  • Sridhar Venkatachalam

    With close to 10 years on Experience in data science and machine learning Have extensively worked on programming languages like R, Python (Pandas), SAS, Pyspark.