Documentation Center

  • Trial Software
  • Product Updates

stats::median

Median value of a data sample

Use only in the MuPAD Notebook Interface.

This functionality does not run in MATLAB.

Syntax

stats::median(x1, x2, …, <Averaged>)
stats::median([x1, x2, …], <Averaged>)
stats::median(s, <c>, <Averaged>)

Description

stats::median(x1, x2, …) returns the median of the data xi.

The median of n sorted values x1 ≤ … ≤ xn is .

The averaged median of n sorted values x1 ≤ … ≤ xn is .

For odd n, both the median and the averaged median coincide with the element of the sorted data list. For even n, the median is , whilst the averaged median is .

The median coincides with the -quantile of the data: the calls stats::median(data <Averaged>) and stats::empiricalQuantile(data)(1/2 <Averaged>) are equivalent. See the help page of stats::empiricalQuantile for details on the parameters specifying the data.

The column index c is optional if the data are given by a stats::sample object containing only one non-string column. Cf. Example 3.

External statistical data stored in an ASCII file can be imported into a MuPAD® session via import::readdata. In particular, see Example 1 of the corresponding help page.

Examples

Example 1

We calculate the median of a sequence of five values:

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

Alternatively, data may be passed as a list:

stats::median([2, 7, 3, 9/2, 11, 12]),
stats::median([2, 7, 3, 9/2, 11, 12], Averaged)

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)

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, there is no need to specify the index of the column, since it is the only non-string data column in the sample:

stats::median(%)

Parameters

x1, x2, …

The statistical data: real numerical values.

s

A sample of domain type stats::sample

c

A column index of the sample s: a positive integer. This column provides the data x1, x2 etc.

Options

Averaged

Return the averaged median value

Return Values

arithmetical expression. FAIL is returned if the data sample is empty.

See Also

MuPAD Functions

Was this topic helpful?