Re: [Rd] Sort in ecdf

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Wed, 30 May 2007 21:39:32 +0200

>>>>> "Shiazy" == Shiazy Fuzzy <shiazy_at_gmail.com>
>>>>> on Wed, 30 May 2007 20:07:24 +0200 writes:

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

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

    Shiazy> What do you think?

I agree, and I have removed the 2nd one. Thank you for your note.

Martin

    Shiazy> Sincerely,

    Shiazy> -- Marco

    Shiazy> ______________________________________________
    Shiazy> R-devel_at_r-project.org mailing list     Shiazy> https://stat.ethz.ch/mailman/listinfo/r-devel

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 30 May 2007 - 19:44:43 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Wed 30 May 2007 - 21:34:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.