Bug 16532 - Incorrect result from which.max and which.min for boolean vectors
Summary: Incorrect result from which.max and which.min for boolean vectors
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Documentation (show other bugs)
Version: R 3.2.1
Hardware: All All
: P5 normal
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2015-09-09 20:39 UTC by tz-lom
Modified: 2015-09-10 13:16 UTC (History)
4 users (show)

See Also:


Attachments
Suggested documentation patch (1.02 KB, patch)
2015-09-10 09:35 UTC, Mikko Korpela
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description tz-lom 2015-09-09 20:39:47 UTC
According to documentation,
"""
For a logical vector x, which.min(x) and which.max(x) return the index of the first FALSE or TRUE, respectively.
"""

but

> which.min(c(T,T,T))
[1] 1
> which.max(c(F,F,F))
[1] 1
Comment 1 Peter Dalgaard 2015-09-09 21:59:26 UTC
A documentation blunder, surely.
Comment 2 tz-lom 2015-09-10 07:44:55 UTC
(In reply to Peter Dalgaard from comment #1)
> A documentation blunder, surely.

I don't think so, because function that returns index of first TRUE or 1 if no TRUE was found is useless.
Comment 3 Mikko Korpela 2015-09-10 09:35:52 UTC
Created attachment 1910 [details]
Suggested documentation patch

Clarifies that both FALSE and TRUE values being present in the input vector is a sufficient condition for the function to work as assumed by the original poster.

Adds 'na.rm = TRUE' to the comparable 'which(x == min(x))' and 'which(x == max(x))' calls.
Comment 4 Mikko Korpela 2015-09-10 09:40:28 UTC
The documentation patch is for R development version r69347.
Comment 5 Duncan Murdoch 2015-09-10 11:06:14 UTC
Comment on attachment 1910 [details]
Suggested documentation patch

Surely a better fix for the first sentence is just to remove it, or remind readers of the fact that FALSE < TRUE.

The second fix makes sense.
Comment 6 Martin Maechler 2015-09-10 13:10:48 UTC
(In reply to Duncan Murdoch from comment #5)
> Comment on attachment 1910 [details]
> Suggested documentation patch
> 
> Surely a better fix for the first sentence is just to remove it, or remind
> readers of the fact that FALSE < TRUE.

You are right: From one point of view that small paragraph is entirely superfluous.   On the other hand I have seen many many inefficient and inelegant ways to "search" for the first TRUE/FALSE in a logical vector,  and that's why I had added the sentence (which is only correct with the proposed specification) in the first place. 

I will move it to a \note{...} .. as you are right it does not belong to the description.

> 
> The second fix makes sense.

I'll commit a change "in a moment".