R Program to find maximum and minimum value of a given vector

What is a vector in R? 

Vector can be defined as a data type that includes a list of values of the same type. each value in a vector is called its components, separated by commas. For example, consider C = (1, 2, 3, 4, 5, 6) and it is a vector that contains a list of values of int type. 

How to find the maximum and minimum vector in R program?

To find a vector maximum and minimum using the R program, we are using built-in functions max, min for this calculation. The values are passed to these functions directly here. The min() function in R computes the minimum value or data frame. And the max() function in R computes the maximum value or data frame.

min(x, na.rm = FALSE)
max(x, na.rm = FALSE)
 #where x is numeric or character vector and na.rm – a logical indicating whether missing values should be removed


STEP 1: Assign variable num with vector values

STEP 2: Use the built-in functions

STEP 3: First print original values

STEP 4: call max() with an argument as num to find maximum value

STEP 5: call min() with an argument as num to find minimum value

STEP 6: print the result of each function

R Source Code

                                          num = c(5, 10, 15, 20, 25, 30)
print('Original vector is:')
print(paste("Maximum value of the said vector:",max(num)))
print(paste("Minimum value of the said vector:",min(num)))


[1] "Original vector is:"
[1] 5, 10, 15, 20, 25, 30
[1] "Maximum value of the said vector: 30"
[1] "Minimum value of the said vector: 5"