arrange {dplyr} | R Documentation |
Order tbl rows by an expression involving its variables.
arrange(.data, ...) ## S3 method for class 'grouped_df' arrange(.data, ..., .by_group = FALSE)
.data |
A tbl. All main verbs are S3 generics and provide methods
for |
... |
Comma separated list of unquoted variable names, or expressions
involving variable names. Use |
.by_group |
If |
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()
.
Unlike base sorting with sort()
, NA
are:
always sorted to the end for local data, even when wrapped with desc()
.
treated differently for remote data, depending on the backend.
When applied to a data frame, row names are silently dropped. To preserve,
convert to an explicit variable with tibble::rownames_to_column()
.
Other single table verbs: filter
,
mutate
, select
,
slice
, summarise
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)