To reverse a list in R, you can use the built-in rev()
function.
In this example,
original_list
containing elements in the original order.rev()
function to reverse the list.original_list <- c(1, 2, 3, 4, 5)
reversed_list <- rev(original_list)
print("Reversed list:", reversed_list)
Reversed list: 5 4 3 2 1
In this example,
original_list
.rev()
function to reverse the list.original_list <- c("apple", "banana", "orange", "grape")
reversed_list <- rev(original_list)
print("Reversed list:", reversed_list)
Reversed list: grape orange banana apple
In this tutorial, we learned How to Reverse a List in R language with well detailed examples.