w3resource

R Programming: Reverse the order of given vector

R Programming: Vector Exercise-20 with Solution

Write a R program to reverse the order of given vector.

Sample Solution :

R Programming Code :

v = c(0, 10, 10, 10, 20, 30, 40, 40, 40, 50, 60)
print("Original vector-1:")
print(v)
rv = rev(v)
print("The said vector in reverse order:")
print(rv)

Sample Output:

[1] "Original vector-1:"
 [1]  0 10 10 10 20 30 40 40 40 50 60
[1] "The said vector in reverse order:"
 [1] 60 50 40 40 40 30 20 10 10 10  0                        

R Programming Code Editor:



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

Previous: Write a R program to find the elements of a given vector that are not in another given vector.
Next: Wrtie a R program to concatenate a 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.