arrange: Arrange rows by variables

Description Usage Arguments Value Locales Missing values Tidy data See Also Examples

View source: R/manip.r

Description

Order tbl rows by an expression involving its variables.

Usage

1
2
3
4
arrange(.data, ...)

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

Arguments

.data

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, or expressions involving variable names. Use desc() to sort a variable in descending order.

.by_group

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

Value

An object of the same class as .data.

Locales

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

Missing values

Unlike base sorting with sort(), NA are:

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

Examples

1
2
3
4
5
6
7
8
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)

hadley/dplyr documentation built on Oct. 17, 2019, 4:45 p.m.