Skip to content
Related Articles

Related Articles

Improve Article
Reordering of a Data Set in R Programming – arrange() Function
  • Last Updated : 15 Jun, 2020

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:




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

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:




# 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) 

Output:

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