Statistics - Maple Programming Help

Home : Support : Online Help : Statistics and Data Analysis : Statistics Package : Data Manipulation : Statistics/OrderByRank

Statistics

 OrderByRank
 order data items according to their ranks

 Calling Sequence OrderByRank(X, R, options)

Parameters

 X - R - ranks options - (optional) equation(s) of the form option=value where option is one of order or unique; specify options for the OrderByRank function

Description

 • The OrderByRank command orders the elements/rows of X according to their ranks.
 • The first parameter X is the data set - given as e.g. a Vector.
 • The second parameter R is the ranks data (also specified as a data set).

Options

 The options argument can contain one or more of the options shown below.
 • order = ascending or descending -- Indicate whether the elements of X should be sorted in the ascending or descending order. The default value is order=ascending.
 • unique=truefalse -- If this option is set to true, all multiple occurrences of elements from X will be removed. The default value is unique=false.

Notes

 • The OrderByRank command creates a copy of the original Array.

Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $A≔\mathrm{Array}\left(\left[a,b,c,d,e,f,g,h\right]\right)$
 ${A}{≔}\left[\begin{array}{cccccccc}{a}& {b}& {c}& {d}& {e}& {f}& {g}& {h}\end{array}\right]$ (1)
 > $B≔\mathrm{Array}\left(\left[5,4,3,7,6,2,8,1\right]\right)$
 ${B}{≔}\left[\begin{array}{cccccccc}{5}& {4}& {3}& {7}& {6}& {2}& {8}& {1}\end{array}\right]$ (2)
 > $\mathrm{OrderByRank}\left(A,B\right)$
 $\left[\begin{array}{cccccccc}{h}& {f}& {c}& {b}& {a}& {e}& {d}& {g}\end{array}\right]$ (3)

Sort two arrays simultaneously.

 > $A≔\mathrm{Array}\left(\left[5.,4.,3.,7.,6.,2.,8.,1.\right]\right)$
 ${A}{≔}\left[\begin{array}{cccccccc}{5.}& {4.}& {3.}& {7.}& {6.}& {2.}& {8.}& {1.}\end{array}\right]$ (4)
 > $B≔\mathrm{Array}\left(\left[a,b,c,d,e,f,g,h\right]\right)$
 ${B}{≔}\left[\begin{array}{cccccccc}{a}& {b}& {c}& {d}& {e}& {f}& {g}& {h}\end{array}\right]$ (5)
 > $C≔\mathrm{Rank}\left(A\right)$
 ${C}{≔}\left[\begin{array}{cccccccc}{5}& {4}& {3}& {7}& {6}& {2}& {8}& {1}\end{array}\right]$ (6)
 > $\mathrm{OrderByRank}\left(A,C\right)$
 $\left[\begin{array}{cccccccc}{1.}& {2.}& {3.}& {4.}& {5.}& {6.}& {7.}& {8.}\end{array}\right]$ (7)
 > $\mathrm{OrderByRank}\left(B,C\right)$
 $\left[\begin{array}{cccccccc}{h}& {f}& {c}& {b}& {a}& {e}& {d}& {g}\end{array}\right]$ (8)
 > $X≔\mathrm{Array}\left(\left[a,b,c,d\right]\right)$
 ${X}{≔}\left[\begin{array}{cccc}{a}& {b}& {c}& {d}\end{array}\right]$ (9)
 > $Y≔\mathrm{Array}\left(\left[2,3,4,1\right]\right)$
 ${Y}{≔}\left[\begin{array}{cccc}{2}& {3}& {4}& {1}\end{array}\right]$ (10)
 > $\mathrm{OrderByRank}\left(X,Y\right)$
 $\left[\begin{array}{cccc}{d}& {a}& {b}& {c}\end{array}\right]$ (11)
 > $Z≔\mathrm{Array}\left(\left[2,3,4,3\right]\right)$
 ${Z}{≔}\left[\begin{array}{cccc}{2}& {3}& {4}& {3}\end{array}\right]$ (12)
 > $\mathrm{OrderByRank}\left(X,Z\right)$
 > $\mathrm{OrderByRank}\left(X,Z,\mathrm{unique}=\mathrm{true}\right)$
 $\left[\begin{array}{ccc}{a}& {d}& {c}\end{array}\right]$ (13)
 > $A≔\mathrm{Array}\left(1..6,1..2,\left[\left[10,a\right],\left[5,b\right],\left[-2,c\right],\left[3,d\right],\left[7,e\right],\left[20,f\right]\right]\right)$
 ${A}{≔}\left[\begin{array}{cc}{10}& {a}\\ {5}& {b}\\ {-2}& {c}\\ {3}& {d}\\ {7}& {e}\\ {20}& {f}\end{array}\right]$ (14)
 > $R≔\mathrm{Rank}\left(A\left[1..-1,1\right]\right)$
 ${R}{≔}\left[\begin{array}{cccccc}{5}& {3}& {1}& {2}& {4}& {6}\end{array}\right]$ (15)
 > $\mathrm{OrderByRank}\left(A,R\right)$
 $\left[\begin{array}{cc}{-2}& {c}\\ {3}& {d}\\ {5}& {b}\\ {7}& {e}\\ {10}& {a}\\ {20}& {f}\end{array}\right]$ (16)