Write a R program to find nth highest value in a given vector.
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
total answers (1)
start bookmarking useful questions and collections and save it into your own study-lists, login now to start creating your own collections.
Sample Output:
need an explanation for this answer? contact us directly to get an explanation for this answer