Skip to content
Related Articles

Related Articles

Improve Article

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

  • Last Updated : 17 Jun, 2020

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

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
My Personal Notes arrow_drop_up
Recommended Articles
Page :