help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Difference between NaN and NA?


From: Jaroslav Hajek
Subject: Re: Difference between NaN and NA?
Date: Thu, 8 Apr 2010 09:16:07 +0200

On Thu, Apr 8, 2010 at 9:03 AM, David Bateman <address@hidden> wrote:
> Jaroslav Hajek wrote:
>>
>> On Thu, Apr 8, 2010 at 8:13 AM, Matthias Brennwald
>> <address@hidden> wrote:
>>
>>>
>>> Dear all
>>>
>>> What is the difference between NaN and NA? I guess there are "different"
>>> differences, like technical aspects related to the internal programming of
>>> Octave (or its commercial counterpart), but also related to conventions
>>> when/how to use NaN or NA.
>>>
>>> I tend to not use NA, and use NaN instead in more or less all situations
>>> where a variable does not contain a true numerical value. I do this mainly
>>> because I don't now the difference between the two and therefore decided not
>>> to mix them. However, I suspect it might be useful to use both in a somehow
>>> meaningful manner. I'd therefore like to know in which situations you'd use
>>> NaN rather than NA (and vice versa).
>>>
>>>
>>
>>
>> I think that NA was introduced into Octave by D. Bateman to make
>> importing data from R easier.
>
> No it existed before I touched it..
>
>> NA is just a special kind of NaN that is
>> displayed differently and is detectable by the "isna" function. Most
>> of Octave is however not aware of NA's and just treats them like NaNs,
>> so
>>
>
> Exact.. NaN is flagged by a particular exponent in IEEE754, so there are
> many values of the mantissa that still give a NaN.. What we did was pick one
> of these to represent the NA value.. Initially the NA value was chosen to be
> the same as in R. However, when introducing single precision values this
> value of NA didn't result in an easy conversion of single NA to a double NA
> value, so I changed the double NA value to facilitate this conversion.
> However, the load function supports both the old and new NA value.
>
> I asked on the R list if they wanted to change their NA value to allow NA
> values to be transmitted over a pipe from R to Octave and visa versa, but
> got no answer
>
> D.
>

In the current situation, NA's do no harm in Octave, but they're also
not much useful, because most functions ignore them, for instance,
mean ([1,2,3,NA]) is NA etc.
On the contrary, inserting checks for NA's everywhere is a good idea
either, because it will slow things down for everyone.

Now that Octave supports OOP, I could imagine an extension package
that provides arrays with missing values as objects,
each object keeping an array and a logical mask indicating missing
values. One could then support lots of operations with these arrays,
that behave "the correct way", instead of the poor support that is
there now.


-- 
RNDr. Jaroslav Hajek, PhD
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]