Currently, the median for an ordered factor is not implemented in base R.
This function is a remedy for this. It allows the computation of “a
median” for ordered factors (see below) and overwrites the error message for
unordered factors from median.default
(hence, the
function name is median.factor and not median.ordered).
If the length of x
is even, then the median will be the middle value
of the sorted list of elements from x
. If the length of x
is
odd and the two middle values of the sorted list of elements from x
are equal, then the median is one of these (equal) middle values. The only
problematic case is an odd length x
with unequal middle values. In
this case, the median of a numeric vector is normally defined as the mean of
the two middle values. However, for ordered factors the mean is not defined.
The argument ordered_low
cures this problem. If ordered_low =
FALSE
(the default), then the larger of the two middle values is returned
(this value is called ‘hi-median’ in mad
). If
ordered_low = TRUE
, then the smaller of the two middle values is
returned (this value is called ‘low-median’ in
mad
).