What is the max() function in R?
Overview
The max() function in R is used to return the maximum value of a given vector.
Syntax
max(...)
Syntax for the max() function in R
Parameter
The max() function takes ... as a parameter value. This represents the vector objects from which the maximum value is to be determined.
Return value
The max() function returns a numeric value with the maximum value in a vector object.
Example
Let's look at the code below:
# creating vector objectsa <- c(1, 3, 2, 5, 6)b <- c(100, 4, 1)c <- c(99.9, 46, 3, 5)# obtaining the maximum value from the list of vector objectsmax(a, b, c)
Explanation
- Lines 2 to 4: We create vector objects,
a,b, andc. - Line 7: We use the
max()function to obtain the maximum value from the provided vectors. We then print it to the console.