Learn R Programming

DescTools (version 0.99.19)

median.factor: Median for Ordered Factors

Description

Calculate the median for ordered factors. This is not implemented in standard R, as it's not well defined (it is not clear what to do if the median sits between two levels in factors of even length). This function returns the high median and prints a warning if the low median would be different (which is supposed to be a rare event).

Usage

"median"(x, na.rm = FALSE)

Arguments

x
an ordered factor containing the values whose median is to be computed.

na.rm
a logical value indicating whether NA values should be stripped before the computation proceeds.

Value

Details

There's a vivid discussion between experts going on whether this should be defined or not. We'll wait for definitive results and enjoy the function's comfort so far...

See Also

https://stat.ethz.ch/pipermail/r-help/2003-November/042684.html

http://stackoverflow.com/questions/7925102/idiomatic-method-of-finding-the-median-of-an-ordinal

Examples

Run this code
median(d.pizza$quality, na.rm=TRUE)

Run the code above in your browser using DataLab