看看功能sort.list()
,它调用order()
ie。当这部分相当于时间密集型部分(大向量)时,它们将是相同的:
> 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))
}
只是一个参考,microbenchmark以多个表达式作为参数。如果你使用'microbenchmark :: microbenchmark(order = order(a,method =“radix”),sort = sort.list(a,方法= “基数”))' – Gregor