+4 votes
in Programming Languages by (16.6k 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

0 votes
by (33.0k points)

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

...