Q:

Write a R program to find nth highest value in a given vector

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

x = c(10, 20, 30, 20, 20, 25, 9, 26)
print("Original Vectors:")
print(x)
print("nth highest value in a given vector:")
print("n = 1")
n = 1
print(sort(x, TRUE)[n])
print("n = 2")
n = 2
print(sort(x, TRUE)[n])
print("n = 3")
n = 3
print(sort(x, TRUE)[n])
print("n = 4")
n = 4
print(sort(x, TRUE)[n])

Sample Output:

[1] "Original Vectors:"
[1] 10 20 30 20 20 25  9 26
[1] "nth highest value in a given vector:"
[1] "n = 1"
[1] 30
[1] "n = 2"
[1] 26
[1] "n = 3"
[1] 25
[1] "n = 4"
[1] 20

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now