What is the range() function in R?
Overview
The range() function in R is used to return a vector with two elements:
- The first element represents the minimum value of the input vector.
- The second element is the maximum value of the input vector.
Syntax
The range() function takes the syntax below:
range(…, na.rm = FALSE)
Syntax for the range() function in R
Parameter value
The range() function takes the following parameter values:
...: This represents any numeric or character objects or vectors.na.rm: This takes a Boolean value (TRUEorFALSE) indicating if theNaN(Not a Number) values should be omitted or not.
Return value
The range() function returns a vector object holding the result.
# creating an input vector objecta <- c(1, 2, 3, 4, 10, NaN)# calling the range() functionrange(a, na.rm=TRUE)
Explanation
- Line 2: We create a vector object,
a. - Line 5: We implement the
range()function on the object. We print the result to the console.