w3resource

R Programming: Find second highest value in a given vector

R Programming: Vector Exercise-13 with Solution

Write a R program to find second highest value in a given vector.

Sample Solution :

R Programming Code :

x = c(10, 20, 30, 20, 20, 25, 9, 26)
print("Original Vectors:")
print(x)
print("Find second highest value in a given vector:")
l = length(x)
print(sort(x, partial = l-1)[l-1])

Sample Output:

[1] "Original Vectors:"
[1] 10 20 30 20 20 25  9 26
[1] "Find second highest value in a given vector:"
[1] 26                         

R Programming Code Editor:



Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a R program to access the last value in a given vector.
Next: Write a R program to find nth highest value in a given vector.

Test your Programming skills with w3resource's quiz.

What is the difficulty level of this exercise?



Follow us on Facebook and Twitter for latest update.