[R] inclusion criteria help

Aaron J Mackey ajm6q at virginia.edu
Tue Nov 27 18:38:00 CET 2001

On Tue, 27 Nov 2001, Thomas Lumley wrote:

> Actually, which.max already does break ties -- it finds the first maximum.

Sorry, what I meant was: if there are ties, I want to apply additional
logic to decide which is the right row to return (i.e. I may not want the
first row that has the maximum coverage).  I may want to break ties by
finding the row with the minimal "percid" or some other calculated value.

I think it might end up looking something like this:

filter <- function(this.subset) {
   best <- which(this.subset$coverage == max(this.subset$coverage))
   best <- which(this.subset$percid[best] == min(this.subset$percid[best]))
   # any additional logic to narrow down best to the absolute best row index

   # now return the first best row:
   this.subset[best[1], , drop=FALSE]

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list