Reordering of a Data Set in R Programming – arrange() Function

arrange() function in R Language is used for reordering of table rows with the help of column names as expression passed to the function.

Syntax: arrange(x, expr)

Parameters:
x: data set to be reordered
expr: logical expression with column name

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to reorder a data set 
  
# Loading library
library(dplyr)
  
# Calling dataset
x <- BOD
x
  
# Calling arrange() function
arrange(x, demand)

chevron_right


Output:

  Time demand
1    1    8.3
2    2   10.3
3    3   19.0
4    4   16.0
5    5   15.6
6    7   19.8
  Time demand
1    1    8.3
2    2   10.3
3    5   15.6
4    4   16.0
5    3   19.0
6    7   19.8

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

# R program to reorder a data set 
  
# Loading library
library(dplyr)
  
# Create a data frame 
d <- data.frame( name = c("Abhi", "Bhavesh", "Chaman", "Dimri"),  
                 age = c(7, 5, 9, 16) ) 
    
# Arranging name according to the age 
d.name<- arrange(d, age) 
print(d.name) 

chevron_right


Output:

     name age
1 Bhavesh   5
2    Abhi   7
3  Chaman   9
4   Dimri  16
My Personal Notes arrow_drop_up

Recommended Posts:


Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.