R Program to reverse a number - rev() Function Last Updated : 15 Jul, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will discuss how to reverse a number in R Programming Language. To reverse a number we will use in built method in R. In R Programming Language rev() function is used to return the reverse version of data objects. The data objects can be defined as Vectors, Data Frames by Columns & by Rows, etc. Syntax: rev(x) Parameter: x: Data object Returns: Reverse of the data object passed R program to reverse a number R # R program to reverse a vector # Create a vector vec <- 1:5 vec # Apply rev() function to vector vec_rev <- rev(vec) vec_rev Output: [1] 1 2 3 4 5[1] 5 4 3 2 1R program to Reverse Columns of a Data Frame R # R program to reverse # columns of a Data Frame # Creating a data.frame data <- data.frame(x1 = 1:5, x2 = 6:10, x3 = 11:15) data # Print reversed example data frame data_rev <- rev(data) data_rev Output: x1 x2 x31 1 6 112 2 7 123 3 8 134 4 9 145 5 10 15 x3 x2 x11 11 6 12 12 7 23 13 8 34 14 9 45 15 10 5 R program to Reverse Rows of a Data Frame R # R program to reverse # rows of a data frame # Creating a data frame data <- data.frame(x1 = 1:5, x2 = 6:10, x3 = 11:15) data # Calling rev() & apply() functions combined data_rev_row_a <- apply(data, 2, rev) data_rev_row_a # Alternative without rev() data_rev_row_b <- data[nrow(data):1, ] data_rev_row_b Output: x1 x2 x31 1 6 112 2 7 123 3 8 134 4 9 145 5 10 15 data_rev_row_a x1 x2 x3[1,] 5 10 15[2,] 4 9 14[3,] 3 8 13[4,] 2 7 12[5,] 1 6 11data_rev_row_b x1 x2 x35 5 10 154 4 9 143 3 8 132 2 7 121 1 6 11ConclusionThe rev function provides a concise and efficient solution for reversing the elements of a vector. It is particularly useful in scenarios where the order of elements needs to be reversed for further analysis or presentation. Comment More infoAdvertise with us Next Article Create a numeric vector in R K kaurbal1698 Follow Improve Article Tags : R Language R DataFrame-Function R Vector-Function R Object-Function R Matrix-Function R List-Function +2 More Similar Reads Replicating a Value specified number of times in R Programming - rep.int() Function rep.int() function in R Language is used to replicate a given value into a specified number of times. Syntax: rep.int(x, times) Parameters: x: specified value times: specified number of times the value get printed Example 1: Python3 # R program to illustrate # rep.int function # Calling the rep.int( 1 min read Get a List of Numbers in the Specified Range in R Programming - seq.int() Function seq.int() function in R Language is used to return a list of numbers in the specified range. Syntax: seq.int(from, to, by) Parameters: from: specified range from to: specified range to by: specified number by which it jumps through returned number Example 1: Python3 # R program to illustrate # seq.i 1 min read Formatting Numbers and Strings in R Programming - format() Function In R programming, the format() function formats numbers, strings and dates to meet presentation needs. It gives formatting features to modify the display of numeric values, strings and date/time information. This function is applied to regulate the number of decimal places, alignment, scientific not 3 min read as.numeric() Function in R The as.numeric() function in R is a crucial tool for data manipulation, allowing users to convert data into numeric form, which is essential for performing mathematical operations and statistical analysis. Overview of the as.numeric() FunctionThe as. numeric() function is part of R's base package an 3 min read Create a numeric vector in R A one-dimensional array containing numerical data is called a numeric vector in R Programming Language. Numerical values, such as integers or real numbers, are often stored and manipulated using numerical vectors. Concepts related to the topicNumerical Data Types: Real and integer numbers may be rep 2 min read Format Number as Percentage in R In this article, we are going to see how to format numbers as percentages in R programming language. Method 1: Using formattable package The "formattable" package provides methods to create formattable vectors and data frame objects. This package in R can be installed and loaded into the working spa 3 min read Like