I would like to use LaTeX 3 to automatically calculate the median of a set of predefined data.
Consider the following example:
\documentclass{article}
\def\waterAa{82}
\def\waterAb{51}
\def\waterAc{144}
\def\waterAd{84}
\def\waterAe{120}
\def\waterAf{148}
\def\waterAg{148}
\def\waterAh{108}
\def\waterAi{160}
\def\waterAj{86}
\begin{document}
\noindent Consider the data set
\begin{equation}
\{\waterAa, \waterAb, \waterAc, \waterAd, \waterAe, \waterAf, \waterAg, \waterAh, \waterAi, \waterAj\}
\end{equation}
To find the median of a data set, we first have to arrange the elements relative to their values:
\begin{equation}
\{\waterAb, \waterAa, \waterAd, \waterAj, \waterAh, \waterAe, \waterAc, \waterAf, \waterAg, \waterAi\}
\end{equation}
Since the number of elements is $10$, the median~$M$ is the average of the fifth and sixth element:
\begin{equation}
M = (\waterAh+\waterAe)/2 = 114.
\end{equation}
\section*{Question}
How to I \emph{automatically} calculate the median of a data set (preferably using \LaTeX 3)?
\end{document}


