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)
Hi, ?min(5,1) #[1] 1 ?min(c(1,5)) #[1] 1 ?min(c(1,5))==min(c(5,1)) #[1] TRUE ? min(c(NA,"bla")) #[1] NA ?min(c("bla",NA)) #[1] NA ?min(c("bla",NA),na.rm=FALSE) #[1] NA ?min(c("bla",NA),na.rm=TRUE) #[1] "bla" A.K. ----- Original Message ----- From: Magnus Thor Torfason <zulutime.net at gmail.com> To: "r-help at r-project.org" <r-help at r-project.org> Cc: Sent: Thursday, September 26, 2013 11:07 AM 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.
Please update your R version (as requested by the posting guide) and repeat. On my version:> min(c(NA,"b"))[1] NA> min(c("b",NA))[1] NA Note that ?min specifically states: "If na.rm is FALSE [the default - BG] an NA value in any of the arguments will cause a value of NA to be returned, otherwise NA values are ignored." Cheers, Bert On Thu, Sep 26, 2013 at 8:07 AM, Magnus Thor Torfason < zulutime.net@gmail.com> 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" > > > 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@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]]
Hi again: After reading Ista's note I tried:> min("bla",NA)[1] "bla" So I stand corrected. This appears to be a bug. -- Bert On Thu, Sep 26, 2013 at 8:07 AM, Magnus Thor Torfason < zulutime.net@gmail.com> 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" > > > 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@r-project.org mailing list > https://stat.ethz.ch/mailman/**listinfo/r-help<https://stat.ethz.ch/mailman/listinfo/r-help> > PLEASE do read the posting guide http://www.R-project.org/** > posting-guide.html <http://www.R-project.org/posting-guide.html> > and provide commented, minimal, self-contained, reproducible code. >-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]]
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.
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" > > > That seems wrong. Would this be considered a bug or is there a way to > explain these results in a different way?I'd call it a bug. The internal code does a lot of tricky things with NA values and type coercion, and it looks as though this particular combination got messed up. I wonder if there are other cases, too? I'll take a look. Duncan Murdoch
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