From maechler at stat.math.ethz.ch  Thu Jul  3 22:08:34 2008
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Thu, 3 Jul 2008 22:08:34 +0200
Subject: [Rd] [.data.frame speedup
In-Reply-To: <e21d304c0807011523y6b47a6ft7dd8edf32d62f7de@mail.gmail.com>
References: <e21d304c0807011120i23d873b9n8a913f54cac7f357@mail.gmail.com>
	<e21d304c0807011523y6b47a6ft7dd8edf32d62f7de@mail.gmail.com>
Message-ID: <18541.12738.106851.758332@cmath-5.math.ethz.ch>

>>>>> "TH" == Tim Hesterberg <timhesterberg at gmail.com>
>>>>>     on Tue, 1 Jul 2008 15:23:53 -0700 writes:

    TH> There is a bug in the standard version of [.data.frame;
    TH> it mixes up handling duplicates and NAs when subscripting rows.

    TH> x <- data.frame(x=1:3, y=2:4, row.names=c("a","b","NA"))
    TH> y <- x[c(2:3, NA),]
    TH> y

    TH> It creates a data frame with duplicate rows, but won't print.

and that's a bug, indeed
("introduced" to R version 2.5.0, when the [.data.frame  code was much
optimized for speed, with quite some care), and I have commited
a fix (and a regression test) to both R-devel and R-patched.

Thanks a lot for the bug report, Tim!

Now about your newly proposed code:
I'm sorry to say that it looks so much different from the source
code in
      https://svn.r-project.org/R/trunk/src/library/base/R/dataframe.R
that I don't think we would accept it as a substitute, easily.

Could you try to provide a minimal patch against the source code
and also a selfcontained example that exhibits the speed gain
you are aiming for ?

Best regards,
Martin Maechler, ETH Zurich

[.........................]


    TH> On Tue, Jul 1, 2008 at 11:20 AM, Tim Hesterberg <timhesterberg at gmail.com>
    TH> wrote:

    >> Below is a version of [.data.frame that is faster
    >> for subscripting rows of large data frames; it avoids calling
    >> duplicated(rows)
    >> if there is no need to check for duplicate row names, when:
    >> i is logical
    >> attr(x, "dup.row.names") is not NULL (S+ compatibility)
    >> i is numeric and negative
    >> i is strictly increasing
    >> 

    TH> [[alternative HTML version deleted]]

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



[Rd] [.data.frame speedup
Martin Maechler