What is the IQR() function in R?

Overview

In R, the IQR() function is used to compute the interquartile range of a given object of numerical values.

The interquartile range of these values is a range where 25% on either side is cut off. Statistically, the interquartile range is the difference between the upper quartile and the lower quartile.

Syntax

IQR(x, na.rm = FALSE, type = 7)
The syntax for the IQR() function in R

Parameters

This function takes the following parameter values:

  • x: This represents the numeric vector. This is a required parameter.

  • na.rm: This takes a logical value, TRUE or FALSE, indicating whether missing values be removed or not.

  • type: This represents an integer selecting one of the many quantile algorithms. This is an oprional parameter.

Return value

This method returns the interquartile range of a given object of numerical values.

Example

# creating a numerical object
x <- c(0:10)
# implementing the IQR() function
IQR(x)

Explanation

  • Line 2: We create an R object, x, containing numerical values from 0 to 10.

  • Line 5: We implement the IQR() function to determine the interquartile range of the set of numbers and print the result to the console.

New on Educative
Learn any Language for FREE all September 🎉
For the entire month of September, get unlimited access to our entire catalog of beginner coding resources.
🎁 G i v e a w a y
30 Days of Code
Complete Educative’s daily coding challenge every day in September, and win exciting Prizes.

Free Resources