Reorder a Data Frame
Arguments
- df
A data frame to be reordered.
- x
A character scalar specifying the column to be reordered.
- y
A character scalar specifying the column to order by if ordering by values.
- group
A character scalar specifying the grouping column (optional).
- order
A character scalar specifying the order type (one of "none", "y", "grouped"). See details.
- dir_order
A logical scalar specifying whether to flip the order.
Details
Ordering takes the following possible values:
* "none": No reordering. * "y": Order by values of y. * "grouped_y": Order by values of y and group. * "x": Order alphabetically by x. * "grouped_x": Order alphabetically by x and group.
Examples
# Example usage
df <- data.frame(col1 = c("b", "a", "c"), col2 = c(10, 25, 3))
reorder_by(df, "col1", "col2")
#> col1 col2
#> 1 c 3
#> 2 b 10
#> 3 a 25