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

William Dunlap wdunlap at tibco.com
Thu Sep 26 17:56:38 CEST 2013


I'd say that is a bug.  Furthermore, min(NA, "bla") returns an integer instead
of a character and the results depend on whether the NA is of class "logical"
or "character".
  > str(min(as.logical(NA), "bla")) # expect character NA
   int NA
  > str(min("bla", as.logical(NA))) # expect character NA
   chr "bla"
  > str(min(as.character(NA), "bla")) # expect character NA
   chr "bla"
  > str(min("bla", as.character(NA))) # expect character NA
   chr "bla"

max(NA,"bla") returns the integer NA but does the na.rm=FALSE correctly.

range() seems to get it all right.

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Magnus Thor Torfason
> Sent: Thursday, September 26, 2013 8:07 AM
> To: r-help at r-project.org
> Subject: [R] min(NA,"bla") != min("bla", NA)
> 
> 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"
> 
> 
> That seems wrong. Would this be considered a bug or is there a way to
> explain these results in a different way?
> 
> Best,
> Magnus
> 
> ps. Tested on R 3.0.1, 32 bit for Windows (as well as some older versions)
> 
> ______________________________________________
> 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