Use radix method in order for grouped sorting
This commit is contained in:
parent
423440b5dc
commit
5bda0e58ad
1 changed files with 12 additions and 2 deletions
|
|
@ -66,7 +66,12 @@ reorder_by <- function(df, x, y, group = "", order = "y", dir_order = 1) {
|
||||||
} else if (order == "grouped_y" && group != "") {
|
} else if (order == "grouped_y" && group != "") {
|
||||||
# Order by group first, then by values of y
|
# Order by group first, then by values of y
|
||||||
df <- df[
|
df <- df[
|
||||||
order(df[[group]], df[[y]], decreasing = c(FALSE, dir_order_lgl)),
|
order(
|
||||||
|
df[[group]],
|
||||||
|
df[[y]],
|
||||||
|
decreasing = c(FALSE, dir_order_lgl),
|
||||||
|
method = "radix"
|
||||||
|
),
|
||||||
]
|
]
|
||||||
df[[x]] <- forcats::fct_inorder(df[[x]])
|
df[[x]] <- forcats::fct_inorder(df[[x]])
|
||||||
} else if (order == "grouped_y" && group == "") {
|
} else if (order == "grouped_y" && group == "") {
|
||||||
|
|
@ -81,7 +86,12 @@ reorder_by <- function(df, x, y, group = "", order = "y", dir_order = 1) {
|
||||||
} else if (order == "grouped_x" && group != "") {
|
} else if (order == "grouped_x" && group != "") {
|
||||||
# Order by group first, then alphabetically by x
|
# Order by group first, then alphabetically by x
|
||||||
df <- df[
|
df <- df[
|
||||||
order(df[[group]], df[[x]], decreasing = c(FALSE, dir_order_lgl)),
|
order(
|
||||||
|
df[[group]],
|
||||||
|
df[[x]],
|
||||||
|
decreasing = c(FALSE, dir_order_lgl),
|
||||||
|
method = "radix"
|
||||||
|
),
|
||||||
]
|
]
|
||||||
df[[x]] <- forcats::fct_inorder(df[[x]])
|
df[[x]] <- forcats::fct_inorder(df[[x]])
|
||||||
} else if (order == "grouped_x" && group == "") {
|
} else if (order == "grouped_x" && group == "") {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue