[R] min(NA,"bla") != min("bla", NA)

Duncan Murdoch murdoch.duncan at gmail.com
Fri Sep 27 01:07:41 CEST 2013


On 13-09-26 5:32 PM, Rolf Turner wrote:
>
> Just to add to the confusion, on my system I get NA --- which I
> understand to be
> the correct value --- from all of min(NA,"bla"), min("bla",NA),
> min(c(NA,"bla")), and
> min(c("bla",NA)).  When I append the argument na.rm=TRUE to each of the
> calls,
> I get "bla" from each.
>
> So, no bug in my system.

I've just built a 3.0.1 version, and I definitely see the bug there. 
What do you get from these expressions?

str(min(NA, "bla"))
str(min("bla", NA))
str(min(NA_character_, "bla"))

I get

 > str(min(NA, "bla"))
  int NA
 > str(min("bla", NA))
  chr "bla"
 > str(min(NA_character_, "bla"))
  chr "bla"

on both Windows and OSX R 3.0.1.  After today's patch, I get

  chr NA

for all three.

Duncan Murdoch



>
>> sessionInfo()
>> R version 3.0.1 (2013-05-16)
>> Platform: x86_64-unknown-linux-gnu (64-bit)
>>
>> locale:
>> [1] C
>>
>> attached base packages:
>> [1] stats     graphics  grDevices utils     datasets  methods base
>>
>> other attached packages:
>> [1] misc_0.0-15
>>
>> loaded via a namespace (and not attached):
>> [1] tools_3.0.1
>
> Are the rest of youse guys using Windoze?  No wonder ....
>
>       cheers,
>
>       Rolf
>
> On 09/27/13 05:55, Duncan Murdoch wrote:
>> On 26/09/2013 11:07 AM, Magnus Thor Torfason wrote:
>>> Just ran these two statements:
>>>
>>>    > min(NA,"bla")
>>> [1] NA
>>>
>>>    > min("bla", NA)
>>> [1] "bla"
>>>
>>> And then reran with explicit na.rm=FALSE
>>>
>>>    > min(NA,"bla", na.rm=FALSE)
>>> [1] NA
>>>
>>>    > min("bla", NA, na.rm=FALSE)
>>> [1] "bla"
>>
>> This should be all fixed now (at least for min and max; it's possible
>> some of the other summary functions still have oddities). It's in
>> R-devel, soon r-patched.  All of the above examples should now give a
>> character NA.
>>
>> Duncan Murdoch
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>



More information about the R-help mailing list