# Calculate the Interquartile Range in R Programming – IQR() Function

function in R Language is used to calculate the interquartile range of a data set.**IQR()**

Mathematically,

IQR = Q3 – Q1

where,

Q3 specifies the median of n largest values

Q1 specifies the median of n smallest values

But, R provides in-built IQR() function to perform the upgiven calculations

Syntax:IQR(x)

Parameters:x:Data set

**Example 1:**

`# R program to calculate IQR value` ` ` `# Defining vector ` `x <` `-` `c(` `5` `, ` `5` `, ` `8` `, ` `12` `, ` `15` `, ` `16` `) ` ` ` `# Print Interquartile range ` `print` `(IQR(x)) ` |

**Output:**

[1] 8.5

**Example 2:**

`# R program to calculate IQR value` ` ` `# Defining a matrix ` `x <` `-` `matrix(c(` `1` `:` `9` `), ` `3` `, ` `3` `)` ` ` `# Print Interquartile range ` `print` `(IQR(x)) ` |

**Output:**

[1] 4