+5 votes
in Programming Languages by (71.8k points)
I want to reverse the elements of a vector. What R function should I use?

E.g.

[1, 2, 3, 4, 5] -> [5, 4, 3, 2, 1]

1 Answer

+1 vote
by (349k points)
selected by
 
Best answer

You can use the rev() function to reverse an R vector.

Here is an example:

> a <- c(1,2,3,4,5,6,7)
> rev(a)
[1] 7 6 5 4 3 2 1

Related questions

+4 votes
1 answer
+5 votes
1 answer
+5 votes
1 answer

...