Max Min in R

Find this useful? Support us: Star on GitHub 6
Category: Math | Language: R

To get the maximum or minimum of two numbers in R, we can use the max() and min() functions respectively.

For example, if we want to find the maximum of two numbers, say 5 and 7, we can simply call the max() function with these two numbers as the arguments as shown below:

max(5, 7)

This returns the output 7, indicating that 7 is the larger of the two numbers.

Similarly, if we want to find the minimum of two numbers, we can call the min() function with the two numbers as below:

min(5, 7)

This returns the output 5, indicating that 5 is the smaller of the two numbers.

We can also store the values in variables and pass them to the functions like so:

x <- 5
y <- 7

max(x, y)
min(x, y)

These will return the same results as before, but now we are using variables instead of literals.