[R] Which.min bug?

Martin Maechler maechler at stat.math.ethz.ch
Sat Feb 24 00:31:59 CET 2001

>>>>> "MM" == Martin Maechler <maechler at stat.math.ethz.ch> writes:

>>>>> "Elliot" == Elliot Williams <ewilliams at ucsd.edu> writes:
    Elliot> Hi, I'm not sure this is a bug, so I thought I'd bounce it off
    Elliot> the help group first.

    Elliot> I had a dataset which I was subsetting, and occasionally I get
    Elliot> an empty subset.  If I don't check for emptiness and go
    Elliot> straight to a which.min call on the subset, the program gets a
    Elliot> big negative number back.

    Elliot> One-line Example:
    >>> which.max(NULL)
    Elliot> [1] -2147483647

    MM> (this happens in C code, by "NA_INTEGER + 1" which unfortunately is
    MM> *not* NA ..)

    Elliot> This caused an indexing error which was hard(ish) to track
    Elliot> down.  Should it just return NA or throw an error?  Should I
    Elliot> re-submit to r-bugs?  Or is there some deep reason for this
    Elliot> behavior that I don't understand?

    MM> Yes it is a bug (and I am the culprit), and the same for
    MM> which.max().  As I have been away for almost two weeks, I'm sorry
    MM> that nobody else has confirmed this.

    MM> I believe, for consistency

    MM>   which.min(v) should return the same as which(min(v) == v)

    MM> and hence should return

    MM>   integer(0)

which I have committed for "R-release", to be version 1.2.2 in a few days.

    MM> here.  Returning NA instead is another intuitive possibility.  What
    MM> do others think?

Martin Maechler <maechler at stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
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