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.