# Re: median function

• Subject: Re: median function
• From: Dick Jackson <djackson(at)dfanning.com>
• Date: Thu, 22 Jul 1999 15:19:25 GMT
• Newsgroups: comp.lang.idl-pvwave
• Organization: Fanning Software Consulting
• References: <37965009.EEFBE62D@ssl.berkeley.edu>
• Xref: news.doit.wisc.edu comp.lang.idl-pvwave:15782

```Hi Harald,

Harald Frey wrote:
>
> I see a problem in the median function and would like to get your
> general opinion.
>
> 1. The median function has no /Nan option like total or mean.

I think you will be happy to know that the newly-released IDL 5.2.1 (see
www.rsinc.com for your update!) has the following release note:

MEDIAN Function Improvement:
----------------------------
The MEDIAN function now treats NaN values as missing data.

> IDL> a=findgen(9)
> IDL> print,total(a),mean(a),median(a)
>       36.0000      4.00000      4.00000
> IDL> a[0]=!values.f_nan
> IDL> print,total(a),mean(a),median(a)
>           NaN          NaN      4.00000
> % Program caused arithmetic error: Floating illegal operand

That was in 5.2, but now in 5.2.1, after the same instructions:

IDL> print,total(a),mean(a),median(a)
NaN          NaN      5.00000

> 2. The Nan values are not properly handled in the determination of the
> median. In the first case the Nan values are interpreted as 0. and in
> the second case as very large.
>
> IDL> a=findgen(9)
> IDL> a[0]=!values.f_nan
> [...]
> IDL> a[1]=!values.f_nan
> IDL> print,a
>           NaN          NaN      2.00000      3.00000      4.00000
> 5.00000
>       6.00000      7.00000      8.00000
> IDL> print,median(a)
>       6.00000
> % Program caused arithmetic error: Floating illegal operand

Again, with the new 5.2.1:

IDL> print,median(a)
5.00000

I think you will find this satisfactory!

Cheers,
--
-Dick

Dick Jackson             Fanning Software Consulting, Canadian Office
djackson@dfanning.com    Calgary, Alberta   Voice/Fax: (403) 242-7398
Coyote's Guide to IDL Programming: http://www.dfanning.com/

```