Get the Minimum and Maximum element of a Vector in R Programming – range() Function

function in R Language is used to get the minimum and maximum values of the vector passed to it as argument.**range()**

Syntax:range(x, na.rm, finite)

Parameters:x:Numeric Vectorna.rm:Boolean value to remove NAfinite:Boolean value to exclude non-finite elements

**Example 1:**

`# R program to find the ` `# minimum and maximum element of a vector` ` ` `# Creating a vector` `x <` `-` `c(` `8` `, ` `2` `, ` `5` `, ` `4` `, ` `9` `, ` `6` `, ` `54` `, ` `18` `)` ` ` `# Calling range() function` `range` `(x)` |

**Output:**

[1] 2 54

**Example 2:**

`# R program to find the ` `# minimum and maximum element of a vector` ` ` `# Creating a vector` `x <` `-` `c(` `8` `, ` `2` `, Inf, ` `5` `, ` `4` `, NA, ` `9` `, ` `54` `, ` `18` `)` ` ` `# Calling range() function` `range` `(x)` ` ` `# Calling range() function` `# excluding NA values` `range` `(x, na.rm ` `=` `TRUE)` ` ` `# Calling range() function` `# excluding finite values` `range` `(x, na.rm ` `=` `TRUE, finite ` `=` `TRUE)` |

**Output:**

[1] NA NA [1] 2 Inf [1] 2 54

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the **DSA Self Paced Course** at a student-friendly price and become industry ready.