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

How to find maximum and minimum vector 

Here we are explaining how to write an R program to find the maximum and minimum value of a given vector. Here we are using built-in functions max, min for this calculation. The vector values are passed to these functions directly here. The min() function in R computes the minimum value of a vector or data frame. And the max() function in R computes the maximum value of a vector 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
 

How maximum and minimum value check is implemented in R Program

Below are the steps used in the R program to find the maximum and minimum of vectors. In this R program, we directly give the values to built-in functions. And print the function result. Here we used variable num for assigning vector values.

ALGORITHM

STEP 1: Assign variable num with vector values

STEP 2: Use the built-in functions

STEP 3: First print original vector values

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

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

STEP 6: print the result of each function

R Source Code

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

OUTPUT

[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"