median

Synopsis

set median(set target)
tset median(tset target, int column)

Description

In its first form, the median built-in computes and returns the median of a set (numeric or alphanumeric). Even though a set is returned, it always contains only one component - the median of the target set.

In its second form, median can operate on multi-column entries. In this case, the median is computed for the column specified by the parameter column; column numbering is zero-based. The returned set contains only one member - it is a member of the target set that has the meidan value in the column specified by column. If the target set has several such members, one is picked and returned at random.

Example

The following code listing gives examples of median being applied to a set of numbers, a set of strings, a mixed set of numbers and strings, and a multi-column edge set.

>> nums = {1, 3, 77, 2234, 2 }
>> median (nums)
3
>> strings = {"foo", "bar", "hello", "strange"}
>> median (strings)
hello
>> median (nums+strings)
77
>> crossP = nums X strings
>> median (crossP, 0)
3 bar
>> median (crossP, 1)
1 hello
>>