Order the rows of a data frame by values of specified columns.
Wrapper arround the arrange()
function. Supports
standard and non standard evaluation.
df_arrange(data, ..., vars = NULL, .by_group = FALSE)
a data frame
One or more unquoted expressions (or variable names) separated by
commas. Used to select a variable of interest. Use
desc()
to sort a variable in descending order.
a character vector containing the variable names of interest.
If TRUE, will sort first by grouping variable. Applies to grouped data frames only.
a data frame
df <- head(ToothGrowth)
df
#> len supp dose
#> 1 4.2 VC 0.5
#> 2 11.5 VC 0.5
#> 3 7.3 VC 0.5
#> 4 5.8 VC 0.5
#> 5 6.4 VC 0.5
#> 6 10.0 VC 0.5
# Select column using standard evaluation
df %>% df_arrange(vars = c("dose", "len"))
#> len supp dose
#> 1 4.2 VC 0.5
#> 2 5.8 VC 0.5
#> 3 6.4 VC 0.5
#> 4 7.3 VC 0.5
#> 5 10.0 VC 0.5
#> 6 11.5 VC 0.5
# Select column using non-standard evaluation
df %>% df_arrange(dose, desc(len))
#> len supp dose
#> 1 11.5 VC 0.5
#> 2 10.0 VC 0.5
#> 3 7.3 VC 0.5
#> 4 6.4 VC 0.5
#> 5 5.8 VC 0.5
#> 6 4.2 VC 0.5