[Rd] Sort in ecdf

Shiazy Fuzzy shiazy at gmail.com
Wed May 30 20:07:24 CEST 2007


Hi!

I've noticed the ecdf() R code (R ver. 2.5.0) contains two call to sort:
--- [R-code] ---
ecdf <- function(x)
        x <- sort(x)
        n <- length(x)
        if (n < 1)
                stop("'x' must have 1 or more non-missing values")
        vals <- sort(unique(x))
        rval <- approxfun(vals, cumsum(tabulate(match(x, vals)))/n,
        method = "constant", yleft = 0, yright = 1, f = 0, ties = "ordered")
        class(rval) <- c("ecdf", "stepfun", class(rval))
        attr(rval, "call") <- sys.call()
        rval
--- [/R-code] ---

I think one of the two calls to sort can be removed, improving the performance.

What do you think?

Sincerely,

-- Marco



More information about the R-devel mailing list