[R] Why does match() treat NaN's as compables; Bug or Feature?
jdnewmil at dcn.davis.ca.us
Sun Feb 28 01:06:41 CET 2016
That is one valid point, but according to IEEE754 "a comparison with NaN always returns an unordered result" which it doesn't do unless the incomparables argument to match is specified. Ick.
Sent from my phone. Please excuse my brevity.
On February 27, 2016 3:34:34 PM PST, Bert Gunter <bgunter.4567 at gmail.com> wrote:
>If I understand you correctly, the "bug" is that you do not understand
>match(). See inline comment below and note carefully the "Value"
>section of ?match.
>"The trouble with having an open mind is that people keep coming along
>and sticking things into it."
>-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>On Sat, Feb 27, 2016 at 2:52 PM, Jason Thorpe <jdthorpe at gmail.com>
>> For some reason `match()` treats `NaN`'s as comparables by default:
>>> x <- c(1,2,3,NaN,4,5)
>>  1 2 3 4 5 6
>> which I can override when using `match()` directly:
>>  1 2 3 NA 5 6
>> but not necessarily when calling a function that uses `match()`
>>  0.2 0.4 0.6 0.8 0.8 1.0
>> Obviously there are workarounds for any given scenario, but the
>> problem is that this behavior causes difficult to discover bugs. For
>> example, the behavior of stats::ecdf is definitely a bug introduced
>> use of `match()` (unless you think NaN == 4 is correct).
>No, you misunderstand. match() returns the POSITION of the match, and
>clearly NaN in the 4th position of table =x matches NaN in x. e.g.
> 1 2 3 4 5 6 4
>> Is there a good reason that NaN's are treated as comparables by
>> his this a bug?
>> For reference, I'm using R version 3.2.3
>> [[alternative HTML version deleted]]
>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> PLEASE do read the posting guide
>> and provide commented, minimal, self-contained, reproducible code.
>R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.
[[alternative HTML version deleted]]
More information about the R-help