
Functions for arranging (sorting) rows.
These are SciViews::R versions with standard evaluation
and formula-based non-standard evaluation (ending with underscore _).
arrange_(
.data = (.),
...,
.by_group = FALSE,
.locale = "C",
.decreasing = FALSE
)A data frame (data.frame, data.table or tibble's tbl_df). If not
provided, the data-dot mechanism injects . as .data= automatically.
Either standard (quoted) column names of data. of formulas like
~col_name (formula-masking).
Logical. If TRUE rows are first arranged by the grouping
variables if any (applies only to grouped data frames). FALSE by default.
The locale to sort character vectors in. If NULL(default),
use the "dplyr.legacy_locale" option (same one as dplyr::arrange()),
and if not specified, it uses a "C" locale.
Sort in decreasing order (no, FALSE, by default)?
A similar object as .data with all columns, all attributes and
groups preserved, but row rearranged according to the specified order.
For the way missing data are handled, see dplyr::arrange().
library(svTidy)
data(mtcars, package = 'datasets')
mtcars <- data.trame::as.data.trame(mtcars)
# Standard evaluation (provide quoted names of the columns to sort)
# You cannot use desc(col) here, but must specify what you want in the
# .decreasing argument
arrange_(mtcars, 'cyl', 'disp', .decreasing = c(FALSE, TRUE))
#> # A data.trame: [32 × 11]
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> Merc 240D 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
#> Merc 230 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
#> Volvo 142E 21.4 4 121 109 4.11 2.78 18.6 1 1 4 2
#> Porsche 914-2 26 4 120. 91 4.43 2.14 16.7 0 1 5 2
#> Toyota Corona 21.5 4 120. 97 3.7 2.46 20.0 1 0 3 1
#> Datsun 710 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> Lotus Europa 30.4 4 95.1 113 3.77 1.51 16.9 1 1 5 2
#> Fiat X1-9 27.3 4 79 66 4.08 1.94 18.9 1 1 4 1
#> Fiat 128 32.4 4 78.7 66 4.08 2.2 19.5 1 1 4 1
#> Honda Civic 30.4 4 75.7 52 4.93 1.62 18.5 1 1 4 2
#> # ℹ 22 more rows
# With formula masking, you can use desc()
arrange_(mtcars, ~cyl, ~desc(disp))
#> # A data.trame: [32 × 11]
#> mpg cyl disp hp drat wt qsec vs am gear carb
#> * <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> Merc 240D 24.4 4 147. 62 3.69 3.19 20 1 0 4 2
#> Merc 230 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2
#> Volvo 142E 21.4 4 121 109 4.11 2.78 18.6 1 1 4 2
#> Porsche 914-2 26 4 120. 91 4.43 2.14 16.7 0 1 5 2
#> Toyota Corona 21.5 4 120. 97 3.7 2.46 20.0 1 0 3 1
#> Datsun 710 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1
#> Lotus Europa 30.4 4 95.1 113 3.77 1.51 16.9 1 1 5 2
#> Fiat X1-9 27.3 4 79 66 4.08 1.94 18.9 1 1 4 1
#> Fiat 128 32.4 4 78.7 66 4.08 2.2 19.5 1 1 4 1
#> Honda Civic 30.4 4 75.7 52 4.93 1.62 18.5 1 1 4 2
#> # ℹ 22 more rows