arrange() method

In R, the arrange() method is used to order the rows based on a specified column. The syntax of arrange() method is specified below-

arrange(dataframeName, columnName)

Example:

In the below code we ordered the data based on the runs from low to high using arrange() function.

R




# import dplyr package
library(dplyr)
 
# create a data frame 
stats <- data.frame(player=c('A', 'B', 'C', 'D'),
                runs=c(100, 200, 408, 19),
                wickets=c(17, 20, NA, 5))
 
# ordered data based on runs
arrange(stats, runs)


Output

  player runs wickets
1      D   19       5
2      A  100      17
3      B  200      20
4      C  408      NA

Data Manipulation in R with Dplyr Package

In this article let’s discuss manipulating data in the R programming language.

In order to manipulate the data, R provides a library called dplyr which consists of many built-in methods to manipulate the data. So to use the data manipulation function, first need to import the dplyr package using library(dplyr) line of code. Below is the list of a few data manipulation functions present in dplyr package.

Function Name

Description

filter()

Produces a subset of a Data Frame.

distinct()

Removes duplicate rows in a Data Frame

arrange()

Reorder the rows of a Data Frame

select()

Produces data in required columns of a Data Frame

rename()

Renames the variable names

mutate()

Creates new variables without dropping old ones.

transmute()

Creates new variables by dropping the old.

summarize()

Gives summarized data like Average, Sum, etc.

Similar Reads

filter() method

The filter() function is used to produce the subset of the data that satisfies the condition specified in the filter() method. In the condition, we can use conditional operators, logical operators, NA values, range operators etc. to filter out data. Syntax of filter() function is given below-...

distinct() method

...

arrange() method

The distinct() method removes duplicate rows from data frame or based on the specified columns. The syntax of distinct() method is given below-...

select() method

...

rename() method

In R, the arrange() method is used to order the rows based on a specified column. The syntax of arrange() method is specified below-...

mutate() & transmute() methods

...

summarize() method

The select() method is used to extract the required columns as a table by specifying the required column names in select() method. The syntax of select() method is mentioned below-...