Median

Ordering functions median

definition

The median of an Attribute in the GeoDMS can be calculated with the Rth_element function, with as second Argument the value 0.5.

The median function in the GeoDMS calculates the middle value for each row of three given attributes. Thus median(a, b, c) :=

median(a, interval(min_elem(b, c), max_elem(b, c))) :=
   a < min_elem(b, c)
      ? min_elem(b, c)
      : max_elem(b, c) < a
         ? max_elem(b, c)
         : a

This can be used to bind a to a given range of allowed values.

syntax

  • median(a, b, c)

conditions

  1. the domain of arguments a, b, and c must match or be void.
  2. the Values unit of arguments a, b, and c must match.
  3. b is known to be not larger than c.

since version

since 2008

example

attribute<uint32> medianABC (ADomain) := median(A, B, C);
A(int32) B(int32) C(int32) medianABC
0 1 2 1
1 -1 4 1
-2 2 2 2
4 0 7 4
999 111 -5 111
null 0 0 0
0 null 0 0
0 0 null 0
null 0 null 0
null null null null

ADomain, nr of rows = 10

The result is Null only when all arguments are null. This follows from the implementation of Min_elem and Max_elem, which return the minimum or maximum defined value of each row.