## `stats::median` -- the median value of discrete data

#### Introduction

`stats::median``(..)` returns the median of discrete data.

#### Call(s)

`stats::median(x1, x2, ..)`
`stats::median([x1, x2, ..])`
`stats::median(s <, c>)`

#### Parameters

`x1, x2, ..` | - | the statistical data: numerical real values.
`s` | - | a sample of domain type `stats::sample`.
`c` | - | an integer representing a column index of the sample `s`. This column provides the data `x1`, `x2` etc.

#### Returns

an arithmetical expression. `FAIL` is returned, if the data are empty.

#### Related Functions

`stats::a_quantil`, `stats::geometric`, `stats::harmonic`, `stats::mean`, `stats::modal`, `stats::quadratic`, `stats::stdev`, `stats::variance`

#### Details

- The median of n sorted values x[1]<= .. <= x[n] is x[(n+1)/2)], if n is odd. It is x[n/2] + x[n/2 + 1])/2, if n is even.
- It coincides with the 1/2-quantile. The call `stats::median``(data)` is equivalent to the call `stats::a_quantil(1/2, data)`. See the help page of `stats::a_quantil` for details on the parameters specifying the data.

#### Example 1

We calculate the median of a sequence of five values:

    >> stats::median(3, 8, 5, 9/2, 11)

                                         5

Alternatively, the data may be passed as a list:

    >> stats::median([3, 8, 5, 9/2, 11])

                                         5

#### Example 2

We create a sample:

    >> stats::sample([[4, 7, 5], [3, 6, 17], [8, 2, 2]])

                                    4  7   5
                                    3  6  17
                                    8  2   2

The median of the second column is 6:

    >> stats::median(%, 2)

                                         6

#### Example 3

We create a sample consisting of one string column and one non-string column:

    >> stats::sample([["1996", 1242], ["1997", 1353], ["1998", 1142]])

                                  "1996"  1242
                                  "1997"  1353
                                  "1998"  1142

The median of the second column is calculated. In this case this column does not have to be specified, since it is the only non-string column in the sample:

    >> stats::median(%)

                                       1242

#### Changes

- The input data can now be provided by a `stats::sample`.

Do you have questions or comments?
Copyright © SciFace Software GmbH & Co. KG 2000