**Central Tendency** is one of the feature of descriptive statistics. Central tendency tells about how the group of data is clustered around the centre value of the distribution. Central tendency performs the following measures:

- Arithmetic Mean
- Geometric Mean
- Harmonic Mean
- Median
- Mode

#### Arithmetic Mean

The arithmetic mean is simply called the average of the numbers which represents the central value of the data distribution. It is calculated by adding all the values and then dividing by the total number of observations.

**Formula:**

**where, **

Xindicates the arithmetic mean

indicates value in data vector

nindicates total number of observations

In R language, arithmetic mean can be calculated by

function.**mean()**

Syntax:mean(x, trim, na.rm = FALSE)

Parameters:

x:Represents object

trim:Specifies number of values to be removed from each side of object before calculating the mean. The value is between 0 to 0.5

na.rm:If TRUE then removes the NA value fromx

**Example:**

`# Defining vector ` `x <` `-` `c(` `3` `, ` `7` `, ` `5` `, ` `13` `, ` `20` `, ` `23` `, ` `39` `, ` `23` `, ` `40` `, ` `23` `, ` `14` `, ` `12` `, ` `56` `, ` `23` `) ` ` ` `# Print mean ` `print` `(mean(x)) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 21.5

#### Geometric Mean

The geometric mean is a type of mean that is computed by multiplying all the data values and thus, shows the central tendency for given data distribution.

**Formula:**

**where, **

Xindicates geometric mean

indicates value in data vector

nindicates total number of observations

and **prod()**

function helps in finding the geometric mean for given set of numbers as there is no direct function for geometric mean.**length()**

Syntax:prod(x)^(1/length(x))

where,

prod()function returns the product of all values present in vectorx

length()function returns the length of vectorx

**Example:**

`# Defining vector ` `x <` `-` `c(` `1` `, ` `5` `, ` `9` `, ` `19` `, ` `25` `) ` ` ` `# Print Geometric Mean ` `print` `(prod(x)^(` `1` `/` `length(x))) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 7.344821

#### Harmonic Mean

Harmonic mean is another type of mean used as another measure of central tendency. It is computed as reciprocal of the arithmetic mean of reciprocals of the given set of values.

**Formula:**

**where, **

Xindicates harmonic mean

indicates value in data vector

nindicates total number of observations

**Example:**

Modifying the code to find the harmonic mean of given set of values.

`# Defining vector ` `x <` `-` `c(` `1` `, ` `5` `, ` `8` `, ` `10` `) ` ` ` `# Print Harmonic Mean ` `print` `(` `1` `/` `mean(` `1` `/` `x)) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 2.807018

#### Median

Median in statistics is another measure of central tendency which represents the middlemost value of a given set of values.

In R language, median can be calculated by

function.**median()**

Syntax:median(x, na.rm = FALSE)

Parameters:

x:It is the data vector

na.rm:If TRUE then removes the NA value fromx

**Example:**

`# Defining vector ` `x <` `-` `c(` `3` `, ` `7` `, ` `5` `, ` `13` `, ` `20` `, ` `23` `, ` `39` `, ` ` ` `23` `, ` `40` `, ` `23` `, ` `14` `, ` `12` `, ` `56` `, ` `23` `) ` ` ` `# Print Median ` `median(x) ` |

*chevron_right*

*filter_none*

**Output:**

[1] 21.5

#### Mode

The mode of a given set of values is the value that is repeated most in the set. There can exist multiple mode values in case if there are two or more values with matching maximum frequency.

**Example 1: Single-mode value**

In R language, there is no function to calculate mode. So, modifying the code to find out the mode for a given set of values.

`# Defining vector ` `x <` `-` `c(` `3` `, ` `7` `, ` `5` `, ` `13` `, ` `20` `, ` `23` `, ` `39` `, ` ` ` `23` `, ` `40` `, ` `23` `, ` `14` `, ` `12` `, ` `56` `, ` ` ` `23` `, ` `29` `, ` `56` `, ` `37` `, ` `45` `, ` `1` `, ` `25` `, ` `8` `) ` ` ` `# Generate frequency table ` `y <` `-` `table(x) ` ` ` `# Print frequency table ` `print` `(y) ` ` ` `# Mode of x ` `m <` `-` `names(y)[which(y ` `=` `=` `max` `(y))] ` ` ` `# Print mode ` `print` `(m) ` |

*chevron_right*

*filter_none*

**Output:**

x 1 3 5 7 8 12 13 14 20 23 25 29 37 39 40 45 56 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 2 [1] "23"

**Example 2: Multiple Mode values**

`# Defining vector ` `x <` `-` `c(` `3` `, ` `7` `, ` `5` `, ` `13` `, ` `20` `, ` `23` `, ` `39` `, ` `23` `, ` `40` `, ` ` ` `23` `, ` `14` `, ` `12` `, ` `56` `, ` `23` `, ` `29` `, ` `56` `, ` `37` `, ` ` ` `45` `, ` `1` `, ` `25` `, ` `8` `, ` `56` `, ` `56` `) ` ` ` `# Generate frequency table ` `y <` `-` `table(x) ` ` ` `# Print frequency table ` `print` `(y) ` ` ` `# Mode of x ` `m <` `-` `names(y)[which(y ` `=` `=` `max` `(y))] ` ` ` `# Print mode ` `print` `(m) ` |

*chevron_right*

*filter_none*

**Output:**

x 1 3 5 7 8 12 13 14 20 23 25 29 37 39 40 45 56 1 1 1 1 1 1 1 1 1 4 1 1 1 1 1 1 4 [1] "23" "56"

## Recommended Posts:

- Getting the Modulus of the Determinant of a Matrix in R Programming - determinant() Function
- Set or View the Graphics Palette in R Programming - palette() Function
- tidyr Package in R Programming
- Get Exclusive Elements between Two Objects in R Programming - setdiff() Function
- Intersection of Two Objects in R Programming - intersect() Function
- Add Leading Zeros to the Elements of a Vector in R Programming - Using paste0() and sprintf() Function
- Clustering in R Programming
- Compute Variance and Standard Deviation of a value in R Programming - var() and sd() Function
- Compute Density of the Distribution Function in R Programming - dunif() Function
- Compute Randomly Drawn F Density in R Programming - rf() Function
- Data Handling in R Programming
- Return a Matrix with Lower Triangle as TRUE values in R Programming - lower.tri() Function
- Print the Value of an Object in R Programming - identity() Function
- Check if Two Objects are Equal in R Programming - setequal() Function
- Random Forest with Parallel Computing in R Programming
- R - Object Oriented Programming
- Check for Presence of Common Elements between Objects in R Programming - is.element() Function
- Check if Elements of a Vector are non-empty Strings in R Programming - nzchar() Function
- Finding the length of string in R programming - nchar() method
- Data Reshaping in R Programming

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.