-
Notifications
You must be signed in to change notification settings - Fork 1k
Closed
Milestone
Description
I wonder whether it is worth to implement sort_by.data.table (R 4.4.0) with internal forder instead of base order, and possibly an 'in_place' argument
Some improvement can be seen in my little test:
library(data.table)
set.seed(1234)
DT <- data.table(x=runif(1e7),y=runif(1e7))
# sort_by.data.frame with "forder" instead of "order"
sort_by2 <- function (x, y, ...)
{
if (inherits(y, "formula"))
y <- .formula2varlist(y, x)
if (!is.list(y))
y <- list(y)
o <- do.call(data.table:::forder, c(unname(y), list(...)))
x[o, , drop = FALSE]
}
microbenchmark::microbenchmark(times = 1,
sort_by2(DT, ~ x + y),
sort_by(DT, ~ x + y)
)
#> Unit: seconds
#> expr min lq mean median uq max
#> sort_by2(DT, ~x + y) 1.068101 1.068101 1.068101 1.068101 1.068101 1.068101
#> sort_by(DT, ~x + y) 2.317193 2.317193 2.317193 2.317193 2.317193 2.317193Created on 2024-12-12 with reprex v2.1.1
Metadata
Metadata
Assignees
Labels
No labels