Here we explain how to write an R program to display the vector elements in the reverse order. Here we are using a built-in function rev(). The rev() function helps to give a reversed version of its argument. The syntax of rev() function is like
rev(x)
Where,
In this R program, we are displaying the original values of the vector first. Then, we directly give the values to built-in functions and print the function result. Here we used variable A for assigning vector values and empty vector Rev for assigning reversed vector.
STEP 1: Assign variable A with vector values
STEP 2: Display the original values of vector
STEP 3: Call the function rev()
into variable Rev as Rev = rev(A)
STEP 4: print the vector Rev
A= c(0, 10, 20, 30, 40, 50, 60)
print("Original vector is:")
print(A)
Rev = rev(A)
print("The vector in reverse order is:")
print(Rev)
[1] "Original vector is:" [1] 0, 10, 20, 30, 40, 50, 60 [1] "The vector in reverse order is:" [1] 60 50 40 30 20 10 0