[R] Which.min bug?

Martin Maechler maechler at stat.math.ethz.ch
Fri Feb 23 23:26:55 CET 2001


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

(this happens in C code, by   "NA_INTEGER + 1"
 which unfortunately is *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?

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

I believe, for consistency

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

and hence should return  

  integer(0)

here.  Returning NA instead is another intuitive possibility.
What 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