From maechler at stat.math.ethz.ch  Wed May 30 21:39:32 2007
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Wed, 30 May 2007 21:39:32 +0200
Subject: [Rd] Sort in ecdf
In-Reply-To: <9d3ef91d0705301107h39f396c8wbfe16df9903d441e@mail.gmail.com>
References: <9d3ef91d0705301107h39f396c8wbfe16df9903d441e@mail.gmail.com>
Message-ID: <18013.54004.275777.751766@stat.math.ethz.ch>

>>>>> "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



[Rd] Sort in ecdf
Martin Maechler