Arrange rows by variables

Use desc() to sort a variable in descending order.

arrange(.data, ...)

# S3 method for grouped_df arrange(.data, ..., .by_group = FALSE)


A tbl. All main verbs are S3 generics and provide methods for tbl_df(), dtplyr::tbl_dt() and dbplyr::tbl_dbi().


Comma separated list of unquoted variable names. Use desc() to sort a variable in descending order.


If TRUE, will sort first by grouping variable. Applies to grouped data frames only.


An object of the same class as .data.


The sort order for character vectors will depend on the collating sequence of the locale in use: see locales().

Tidy data

When applied to a data frame, row names are silently dropped. To preserve, convert to an explicit variable with tibble::rownames_to_column().

See Also

Other single table verbs: filter, mutate, select, slice, summarise

  • arrange
  • arrange.grouped_df
arrange(mtcars, cyl, disp)
arrange(mtcars, desc(disp))

# grouped arrange ignores groups
by_cyl <- mtcars %>% group_by(cyl)
by_cyl %>% arrange(desc(wt))
# Unless you specifically ask:
by_cyl %>% arrange(desc(wt), .by_group = TRUE)
# }
Documentation reproduced from package dplyr, version 0.7.3, License: MIT + file LICENSE

Community examples at Jan 12, 2018 dplyr v0.7.3

``` title <- c('Effective Java','Orientalism','False Impressions','How To Program Java','Making Software') height <- c('123','197','177','238','245') year <- c('2011','2011','3015','1999','1997') books <- data.frame(title, height, year) ##order by the column "title" orderedBooks <- arrange(books, title) ##order by the column "title, year" orderedBooks <- arrange(books, title, year) ##order by the columns "title" in assending: orderedBooks <- arrange(books, desc(title)) ``` [more examples](

filipsch at Feb 21, 2017 dplyr v0.5.0

```r library(dplyr) mtcars %>% arrange(hp) ```