To reverse a vector in R, you can use the `rev()` function.
In this example,
vec
containing elements.rev()
function to reverse the order of elements in the vector.vec <- c(1, 2, 3, 4, 5)
reversed_vec <- rev(vec)
[1] 5 4 3 2 1
In this example,
char_vec
containing strings.rev()
function to reverse the order of strings in the vector.char_vec <- c("apple", "banana", "cherry")
reversed_char_vec <- rev(char_vec)
[1] "cherry" "banana" "apple"
In this tutorial, we learned How to Reverse a Vector in R language with well detailed examples.