Skip to content
Related Articles

Related Articles

Get the Minimum and Maximum element of a Vector in R Programming – range() Function
  • Last Updated : 05 Jun, 2020
GeeksforGeeks - Summer Carnival Banner

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

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

Parameters:
x: Numeric Vector
na.rm: Boolean value to remove NA
finite: 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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :