Package: dplyr


Function: arrange()


1. Arrange the data ascending by teacher last name, then teacher first name, then student id

Review the data (d4)

# A tibble: 4 x 3
   s_id t_last_name t_first_name
  <dbl> <chr>       <chr>       
1    10 simpson     homer       
2    15 simpson     marge       
3    12 simpson     homer       
4    13 flanders    marge       

Arrange the data

  • Note: The default sort is ascending. To sort descending, wrap a variable in desc()
d4 %>% dplyr::arrange(t_last_name, t_first_name, s_id)
# A tibble: 4 x 3
   s_id t_last_name t_first_name
  <dbl> <chr>       <chr>       
1    13 flanders    marge       
2    10 simpson     homer       
3    12 simpson     homer       
4    15 simpson     marge       

Return to Reorder