Returns a reversed copy – with attributes retained.
reverse_vector(x)a reversed vector
This is substantially faster than rev()
x <- factor(letters)
rev(x)
#> [1] z y x w v u t s r q p o n m l k j i h g f e d c b a
#> Levels: a b c d e f g h i j k l m n o p q r s t u v w x y z
reverse_vector(x)
#> [1] 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2
#> [26] 1
if (FALSE) { # \dontrun{
x <- 1:1e7
system.time(rev(x))
system.time(reverse_vector(x))
} # }