Compute Geometric Mean Manually

In this method, the user can calculate manually by using exp(), mean() and log() functions together by passing the parameter as the given data to calculate the geometric mean in the R programming language.

  • exp() function is used to get the exponent from mean data.
  • mean() is used to get the mean from log data
  • log() is used to get the log value.

Syntax:

exp(mean(log(data))) 

Example:

In this example, we are going to calculate the geometric mean of 5 elements in a vector using the exp(), mean() and log() functions together in R language.

R




# create  vector
data=c(1,2,3,4,5)
  
# calculate geometric mean
exp(mean(log(data)))


Output:

[1] 2.605171

How to Calculate Geometric Mean in R?

In this article, we will discuss how to calculate the Geometric Mean in R Programming Language.

We can define the geometric mean as the average rate of return of a set of values calculated using the products of the terms.

Similar Reads

Method 1: Compute Geometric Mean Manually

In this method, the user can calculate manually by using exp(), mean() and log() functions together by passing the parameter as the given data to calculate the geometric mean in the R programming language....

Method 2: Using geometric.mean Function of psych Package

...

Method 3: Calculate Geometric Mean of Columns in Data Frame

In this approach, the user has to first install and import the psych package in the working R console, then the user has to call the geometric.mean() function with the required parameter passed into it to calculate the geometric mean of the given data....