sort.list()
を見てください。それはorder()
を呼び出します。この部分が時間のかかる部分(大きなベクトル)になるときは同じです:
> base::sort.list
function (x, partial = NULL, na.last = TRUE, decreasing = FALSE,
method = c("shell", "quick", "radix"))
{
if (is.integer(x) || is.factor(x))
method <- "radix"
method <- match.arg(method)
if (!is.atomic(x))
stop("'x' must be atomic for 'sort.list'\nHave you called 'sort' on a list?")
if (!is.null(partial))
.NotYetUsed("partial != NULL")
if (method == "quick") {
if (is.factor(x))
x <- as.integer(x)
if (is.numeric(x))
return(sort(x, na.last = na.last, decreasing = decreasing,
method = "quick", index.return = TRUE)$ix)
else stop("method = \"quick\" is only for numeric 'x'")
}
if (is.na(na.last)) {
x <- x[!is.na(x)]
na.last <- TRUE
}
if (method == "radix") {
return(order(x, na.last = na.last, decreasing = decreasing,
method = "radix"))
}
.Internal(order(na.last, decreasing, x))
}
FYIのマイクロベンチマークでは、引数として複数の式が使用されています。別々に実行するのではなく、 'microbenchmark :: microbenchmark(order = order(a、method =" radix ")、sort = sort.list(a、 method = "radix")) ' – Gregor