From 5bda0e58ad232bea6bb57d0b1abc302f3ec2ef24 Mon Sep 17 00:00:00 2001 From: gnoblet Date: Wed, 2 Jul 2025 11:59:56 +0200 Subject: [PATCH] Use radix method in order for grouped sorting --- R/reorder_by.R | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/R/reorder_by.R b/R/reorder_by.R index ad0cf9a..f918cc7 100644 --- a/R/reorder_by.R +++ b/R/reorder_by.R @@ -66,7 +66,12 @@ reorder_by <- function(df, x, y, group = "", order = "y", dir_order = 1) { } else if (order == "grouped_y" && group != "") { # Order by group first, then by values of y 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]]) } 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 != "") { # Order by group first, then alphabetically by x 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]]) } else if (order == "grouped_x" && group == "") {