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. |