GeeksforGeeks App
Open App
Browser
Continue

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

range() function in R Programming Language is used to get the minimum and maximum values of the vector passed to it as an 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

R

 `# 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`

R

 `# 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```
My Personal Notes arrow_drop_up