Learn R Programming

seplyr (version 1.0.4)

arrange_se: Arrange standard interface.

Description

Arrange a data frame by the possibly the group_vars() (optional, but defaults to off) and arrangeTerms. Accepts arbitrary text as arrangeTerms to allow forms such as "desc(gear)". Intent is to arrange only by sets of variables with desc() notations reversals, not by arbitrary expressions over variables. To help enforce this parsing is performed in an empty environment (so expressions such as "gear + carb" deliberately error-out).

Usage

arrange_se(.data, arrangeTerms, ..., .by_group = FALSE, strict = TRUE)

Arguments

.data

data.frame

arrangeTerms

character vector of column expressions to arrange by.

...

not used, force later arguments to bind by name.

.by_group

logical, should data be sorted by grouping variables (if present).

strict

logical if TRUE accept only name and desc(name) terms.

Value

.data arrnaged by arrangeTerms

See Also

arrange, arrange_at

Examples

Run this code
# NOT RUN {
datasets::mtcars %.>%
  arrange_se(., c("cyl", "desc(gear)")) %.>%
  head(.)
# equivilent to dplyr/magrittr pipeline
# arrange(datasets::mtcars, cyl, desc(gear)) %>% head()

# Note: arranging in the presence of groups is subtle.
# As grouping is an annotation, not an ordering (and ordering is
# unfortunately not an annotation).

d <- data.frame(x = 1:6,
                sin_x = sin(1:6),
                grp = rep(c("a", "b"), 3),
                stringsAsFactors = FALSE)

# arranged by sin_x and not by grp
d %.>%
  group_by_se(., "grp") %.>%
  arrange_se(., "sin_x")

# arranged by sin_x and not by grp
d %.>%
  arrange_se(., "sin_x") %.>%
  group_by_se(., "grp")

# arranged by sin_x and not by grp
d %.>%
  group_by_se(., "grp") %.>%
  arrange_se(., "sin_x", .by_group = TRUE)

# arranged by sin_x and not by grp
d %.>%
  arrange_se(., "sin_x", .by_group = TRUE) %.>%
  group_by_se(., "grp")

# }

Run the code above in your browser using DataLab