Sorting in Ascending order
Sorting in ascending order is the default sorting order in arrange() function. The attribute to sort by should be given as an argument to this function.
Example: Sorting the dataframe in ascending order
R
# Installing the loading the package install.packages ( "dplyr" ) library (dplyr) # Creating dataframe gfg = data.frame (Customers = c ( "Roohi" , "James" , "Satish" , "Heera" , "Sehnaaz" , "Joe" , "Raj" , "Simran" , "Priya" , "Tejaswi" ), Product = c ( "Product A" , "Product B" , "Product C" , "Product A" , "Product D" , "Product B" , "Product D" , "Product C" , "Product D" , "Product A" ), Salary = c (514.65, 354.99, 345.44, 989.56, 767.50, 576.90, 878.67, 904.56,123.45, 765.78) ) gfg # Sorting the dataframe in ascending order arrange (gfg, Salary) |
Output :
Sorting DataFrame in R using Dplyr
In this article, we will discuss about how to sort a dataframe in R programming language using Dplyr package. The package Dplyr in R programming language provides a function called arrange() function which is useful for sorting the dataframe.
Syntax :
arrange(.data, …)
The methods given below show how this function can be used in various ways to sort a dataframe.