[Rd] is.numeric (NA + NA) is TRUE, should be FALSE (PR#8745)
Duncan Murdoch
murdoch at stats.uwo.ca
Wed Apr 5 00:53:47 CEST 2006
On 4/4/2006 6:38 PM, cheryl fillekes wrote:
> So this is perfectly consistent then:
>
>> A <- NA
>> B <- NA+NA
>> B
> [1] NA
>> A
> [1] NA
A and B both print as NA, but they are stored differently. A is
logical, B is numeric. You'll also see this in the following tests:
> identical(A, A)
[1] TRUE
> identical(A, B)
[1] FALSE
>> is.numeric (A)
> [1] FALSE
>> is.numeric (B)
> [1] TRUE
>
> And the test based on value rather than type would be:
>
>> !is.na(A)
> [1] FALSE
>> !is.na(B)
> [1] FALSE
Yes, that works.
Duncan Murdoch
>
>
>
> On 4/4/06, Antonio, Fabio Di Narzo <antonio.fabio at gmail.com> wrote:
>> 2006/4/4, cfillekes at gmail.com <cfillekes at 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] FALSE
>>
>> In 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 at r-project.org mailing list
>>> https://stat.ethz.ch/mailman/listinfo/r-devel
>>>
>>
>> Antonio, Fabio Di Narzo.
>>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
More information about the R-devel
mailing list