The harmonic mean is defined as the reciprocal of the arithmetic mean of the reciprocals of the data, or 1 / mean(1 / x), where x contains positive numbers. Write a function harmonic_mean() with arguments x and na.rm = FALSE that gives appropriate feedback:

 

 

(from: Cotton, 2013, Learning R, O’Reilly)