cfillekes at gmail.com
2006-Apr-04 19:38 UTC
[Rd] is.numeric (NA + NA) is TRUE, should be FALSE (PR#8745)
Full_Name: c fillekes Version: Version 2.2.1 (2005-12-20 r36812) OS: Gentoo Linux kernel 2.6.12 Submission from: (NULL) (129.116.71.233) "Not Available" is of course not a numeric: R> is.numeric (NA)[1] FALSE But for some reason, all arithmetic operations on NA's are in fact numeric, even if it's with other NA's.> is.numeric (NA+NA)[1] TRUE> is.numeric (NA^2)[1] TRUE> is.numeric (NA-NA)[1] TRUE> is.numeric (NA*NA)[1] TRUE> is.numeric (NA/NA)[1] TRUE>This is not the expected thing.
Duncan Murdoch
2006-Apr-04 19:52 UTC
[Rd] is.numeric (NA + NA) is TRUE, should be FALSE (PR#8745)
On 4/4/2006 3:38 PM, cfillekes at gmail.com wrote:> Full_Name: c fillekes > Version: Version 2.2.1 (2005-12-20 r36812) > OS: Gentoo Linux kernel 2.6.12 > Submission from: (NULL) (129.116.71.233) > > > > > "Not Available" is of course not a numeric: > R > >> is.numeric (NA) > [1] FALSE > > But for some reason, all arithmetic operations on NA's are > in fact numeric, even if it's with other NA's. > > >> is.numeric (NA+NA) > [1] TRUE >> is.numeric (NA^2) > [1] TRUE >> is.numeric (NA-NA) > [1] TRUE >> is.numeric (NA*NA) > [1] TRUE >> is.numeric (NA/NA) > [1] TRUE >> > > This is not the expected thing.But it is the documented thing, so it is not a bug: "'is.numeric' returns 'TRUE' if its argument is of mode '"numeric"' (type '"double"' or type '"integer"') and not a factor, and 'FALSE' otherwise." The value is irrelevant. You probably want to use "is.numeric(x) && all(is.finite(x))" to get the result you're expecting. Duncan Murdoch
Antonio, Fabio Di Narzo
2006-Apr-04 19:52 UTC
[Rd] is.numeric (NA + NA) is TRUE, should be FALSE (PR#8745)
2006/4/4, cfillekes@gmail.com <cfillekes@gmail.com>:> > Full_Name: c fillekes > Version: Version 2.2.1 (2005-12-20 r36812) > OS: Gentoo Linux kernel 2.6.12 > Submission from: (NULL) (129.116.71.233) > > > > > "Not Available" is of course not a numeric: > R > > > is.numeric (NA) > [1] FALSEIn the help you can read: " 'NA' is a logical constant of length 1 which contains a missing value indicator. 'NA' can be freely coerced to any other vector type except raw. " And in fact:> storage.mode(NA)[1] "logical"> storage.mode(NA+0)[1] "double"> storage.mode(as.numeric(NA))[1] "double"> storage.mode(as.character(NA))[1] "character" So in NA+NA the logical is automatically coerced to a numerical value, and is.numericreturns TRUE, as expected. But for some reason, all arithmetic operations on NA's are> in fact numeric, even if it's with other NA's. > > > > is.numeric (NA+NA) > [1] TRUE > > is.numeric (NA^2) > [1] TRUE > > is.numeric (NA-NA) > [1] TRUE > > is.numeric (NA*NA) > [1] TRUE > > is.numeric (NA/NA) > [1] TRUE > > > > This is not the expected thing.I think this is the expected thing. ______________________________________________> R-devel@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-devel >Antonio, Fabio Di Narzo. [[alternative HTML version deleted]]