Overview - Maple Help

Data Manipulation Commands

 The Statistics package provides various functions for manipulating statistical data. These include sorting, searching, and data selection routines. The following is a list of available commands.

 compute number/total weight of observations compute number/total weight of missing values compute cumulative products compute cumulative sums remove any trend from a set of data compute lagged differences between elements evaluate data using floating-point arithmetic remove data items based on density join data samples order data items according to their ranks rank data items according to their numeric values remove data items satisfying a condition remove data items which belong to the given range remove non-numeric values center and/or scale a set of data select data items satisfying a condition select data items which belong to the given range select non-numeric values apply random permutation to a data sample sort numeric data split matrix data into submatrices compute data frequencies compute cumulative data frequencies trim data set winsorize data set

 • The ArrayTools package provides a number of useful tools for manipulating rectangular arrays. Here is the list of available commands.

 add the elements of an Array provide different view of rectangular Matrix, Vector, or Array true when the Array has no zero entries check for nonzero Array entries append element to Array copy a block of several segments of elements from one Matrix, Vector, or Array to another shift Array data provide real view of a complex Matrix, Vector, or Array Array concatenation copy portion of Matrix, Vector, or Array to another perform in-place data transpose extract the diagonals from a Matrix or create a diagonal Matrix size of an Array in each dimension element-wise division of Array entries element-wise multiplication of Array entries element-wise power of Array entries extend Array with additional elements fill portion of Matrix, Vector, or Array with specified value reverse order of elements in an Array compute a general inner product of two Arrays compute a general outer product of two Arrays true when the Array has a nonzero entry true when the Array has a zero entry insert an element in an Array compare Arrays for equality true when the Array has only zero entries return the lower triangular region of a matrix multiply rows of an array return the number of elements in an Array permute dimensions of an Array inverse permute dimensions of an Array randomly generate scalars, Matrices, and Arrays of values drawn from a uniform or normal distribution reduce the elements of an Array by a function generate an array of numbers with specified spacing in a given range remove entries and shrink an Array remove singleton Array dimensions Array replication create a reshaped copy of a Matrix, Vector, or Array reverse a Matrix, Vector, or Array accumulate the elements of an Array by a function return the indices of nonzero elements of the given Array return the size of an Array in each dimension suggest Array datatype for an operation on two Arrays suggest rtable order for an operation on two rtables suggest rtable subtype for an operation on two rtables compute the upper triangular  Matrix

Examples

 > $\mathrm{with}\left(\mathrm{Statistics}\right):$
 > $X≔\mathrm{Sample}\left(\mathrm{Normal}\left(0,1\right),100\right)$
 ${X}{≔}\left[\begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}{-1.07242412799827}& {-0.329077870547065}& {-0.617091936909790}& {0.214466745245291}& {-0.0254281280423846}& {1.72882128417783}& {-1.63485675434390}& {1.57117217175430}& {0.170358421410408}& {1.00647840875181}& {0.268712679158310}& {-1.46598044695878}& {-0.0357578538394966}& {-0.00650336346263664}& {-0.0571830022332381}& {-0.184600094624929}& {0.203855402371112}& {-0.0988718240271234}& {-0.0826980970419822}& {-0.168119128121408}& {0.162021299867933}& {-0.675918709672617}& {-0.440797644048532}& {0.896019985259550}& {0.461022953380023}& {1.27797705227385}& {0.234565961794581}& {-0.0362744912936830}& {-0.448848123512147}& {-1.16737308532471}& {-1.21794288394124}& {-1.15469196092625}& {0.109659323283598}& {-0.619809380641282}& {0.642151004644923}& {-0.170770918098244}& {-0.820052241027982}& {1.34633519663234}& {-0.986038560158125}& {-0.965838793499848}& {-1.36462571980574}& {1.65007871956408}& {1.34804151352017}& {-1.02537392618659}& {0.229788060863910}& {1.48493457968053}& {-1.30030905411587}& {-0.376131116236207}& {0.0617841966672065}& {0.801907829141039}& {-0.129975470550859}& {0.112484530604133}& {0.630360591794658}& {-0.0208959396841725}& {-0.830442822997399}& {-0.262652510141184}& {-0.700300261968008}& {1.95556905861273}& {-0.259474165622608}& {-0.0820850625624299}& {1.21557945262500}& {-0.983131813759657}& {1.93069064888935}& {0.122735108586753}& {0.432945421151540}& {-0.524443817862805}& {0.224215551927832}& {-0.414225568098372}& {0.0355261362296387}& {1.98371209767999}& {2.21337958939036}& {0.881229888626876}& {0.886856450560421}& {-0.861665947308802}& {-0.906611303340893}& {-0.876730984349719}& {-0.217490459619989}& {-0.336155174289136}& {0.549376576019130}& {-1.19754843404833}& {-0.927510339539523}& {-1.32995060542228}& {-1.13043603146978}& {1.27187025067002}& {-1.47651546344906}& {1.61338249093609}& {-0.685342069367486}& {1.08241290092064}& {-0.776734900479867}& {-0.555481438094644}& {1.07239184776825}& {0.0713529776295548}& {-0.182122924489555}& {0.628549543618577}& {-0.725850645010288}& {-0.413380338600023}& {1.54241530115661}& {-0.220309427423809}& {-0.840816024752715}& {0.385066012066646}\end{array}\right]$ (1)

Select only values between -2 and 2;

 > $Y≔\mathrm{SelectInRange}\left(X,-2..2\right)$
 ${Y}{≔}\left[\begin{array}{ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}{-1.07242412799827}& {-0.329077870547065}& {-0.617091936909790}& {0.214466745245291}& {-0.0254281280423846}& {1.72882128417783}& {-1.63485675434390}& {1.57117217175430}& {0.170358421410408}& {1.00647840875181}& {0.268712679158310}& {-1.46598044695878}& {-0.0357578538394966}& {-0.00650336346263664}& {-0.0571830022332381}& {-0.184600094624929}& {0.203855402371112}& {-0.0988718240271234}& {-0.0826980970419822}& {-0.168119128121408}& {0.162021299867933}& {-0.675918709672617}& {-0.440797644048532}& {0.896019985259550}& {0.461022953380023}& {1.27797705227385}& {0.234565961794581}& {-0.0362744912936830}& {-0.448848123512147}& {-1.16737308532471}& {-1.21794288394124}& {-1.15469196092625}& {0.109659323283598}& {-0.619809380641282}& {0.642151004644923}& {-0.170770918098244}& {-0.820052241027982}& {1.34633519663234}& {-0.986038560158125}& {-0.965838793499848}& {-1.36462571980574}& {1.65007871956408}& {1.34804151352017}& {-1.02537392618659}& {0.229788060863910}& {1.48493457968053}& {-1.30030905411587}& {-0.376131116236207}& {0.0617841966672065}& {0.801907829141039}& {-0.129975470550859}& {0.112484530604133}& {0.630360591794658}& {-0.0208959396841725}& {-0.830442822997399}& {-0.262652510141184}& {-0.700300261968008}& {1.95556905861273}& {-0.259474165622608}& {-0.0820850625624299}& {1.21557945262500}& {-0.983131813759657}& {1.93069064888935}& {0.122735108586753}& {0.432945421151540}& {-0.524443817862805}& {0.224215551927832}& {-0.414225568098372}& {0.0355261362296387}& {1.98371209767999}& {0.881229888626876}& {0.886856450560421}& {-0.861665947308802}& {-0.906611303340893}& {-0.876730984349719}& {-0.217490459619989}& {-0.336155174289136}& {0.549376576019130}& {-1.19754843404833}& {-0.927510339539523}& {-1.32995060542228}& {-1.13043603146978}& {1.27187025067002}& {-1.47651546344906}& {1.61338249093609}& {-0.685342069367486}& {1.08241290092064}& {-0.776734900479867}& {-0.555481438094644}& {1.07239184776825}& {0.0713529776295548}& {-0.182122924489555}& {0.628549543618577}& {-0.725850645010288}& {-0.413380338600023}& {1.54241530115661}& {-0.220309427423809}& {-0.840816024752715}& {0.385066012066646}\end{array}\right]$ (2)

Select only values between 5th and 95th percentiles (trim).

 > $Z≔\mathrm{Trim}\left(X,5,95\right)$
 ${Z}{≔}\begin{array}{c}\left[\begin{array}{c}{-1.30030905411587}\\ {-0.861665947308802}\\ {-1.19754843404833}\\ {-1.16737308532471}\\ {-1.15469196092625}\\ {-1.13043603146978}\\ {-1.02537392618659}\\ {-0.927510339539523}\\ {-0.965838793499848}\\ {-0.986038560158125}\\ {⋮}\end{array}\right]\\ \hfill {\text{90 element Vector[column]}}\end{array}$ (3)

Replace extreme points with the values of the 5th or the 95th percentile (whichever is closer).

 > $W≔\mathrm{Winsorize}\left(X,5,95\right)$
 ${W}{≔}\left[\begin{array}{cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc}{-1.07242412799827}& {-0.329077870547065}& {-0.617091936909790}& {0.214466745245291}& {-0.0254281280423846}& {1.72882128417783}& {-1.30030905411587}& {1.57117217175430}& {0.170358421410408}& {1.00647840875181}& {0.268712679158310}& {-1.30030905411587}& {-0.0357578538394966}& {-0.00650336346263664}& {-0.0571830022332381}& {-0.184600094624929}& {0.203855402371112}& {-0.0988718240271234}& {-0.0826980970419822}& {-0.168119128121408}& {0.162021299867933}& {-0.675918709672617}& {-0.440797644048532}& {0.896019985259550}& {0.461022953380023}& {1.27797705227385}& {0.234565961794581}& {-0.0362744912936830}& {-0.448848123512147}& {-1.16737308532471}& {-1.21794288394124}& {-1.15469196092625}& {0.109659323283598}& {-0.619809380641282}& {0.642151004644923}& {-0.170770918098244}& {-0.820052241027982}& {1.34633519663234}& {-0.986038560158125}& {-0.965838793499848}& {-1.30030905411587}& {1.65007871956408}& {1.34804151352017}& {-1.02537392618659}& {0.229788060863910}& {1.48493457968053}& {-1.30030905411587}& {-0.376131116236207}& {0.0617841966672065}& {0.801907829141039}& {-0.129975470550859}& {0.112484530604133}& {0.630360591794658}& {-0.0208959396841725}& {-0.830442822997399}& {-0.262652510141184}& {-0.700300261968008}& {1.72882128417783}& {-0.259474165622608}& {-0.0820850625624299}& {1.21557945262500}& {-0.983131813759657}& {1.72882128417783}& {0.122735108586753}& {0.432945421151540}& {-0.524443817862805}& {0.224215551927832}& {-0.414225568098372}& {0.0355261362296387}& {1.72882128417783}& {1.72882128417783}& {0.881229888626876}& {0.886856450560421}& {-0.861665947308802}& {-0.906611303340893}& {-0.876730984349719}& {-0.217490459619989}& {-0.336155174289136}& {0.549376576019130}& {-1.19754843404833}& {-0.927510339539523}& {-1.30030905411587}& {-1.13043603146978}& {1.27187025067002}& {-1.30030905411587}& {1.61338249093609}& {-0.685342069367486}& {1.08241290092064}& {-0.776734900479867}& {-0.555481438094644}& {1.07239184776825}& {0.0713529776295548}& {-0.182122924489555}& {0.628549543618577}& {-0.725850645010288}& {-0.413380338600023}& {1.54241530115661}& {-0.220309427423809}& {-0.840816024752715}& {0.385066012066646}\end{array}\right]$ (4)
 > $W\left[1..10\right]$
 $\left[\begin{array}{cccccccccc}{-1.07242412799827}& {-0.329077870547065}& {-0.617091936909790}& {0.214466745245291}& {-0.0254281280423846}& {1.72882128417783}& {-1.30030905411587}& {1.57117217175430}& {0.170358421410408}& {1.00647840875181}\end{array}\right]$ (5)

Sort 2-D array according to the numeric values in the second column.

 > $A≔⟨⟨\mathrm{seq}\left(i,i=1..10\right)⟩|⟨\mathrm{seq}\left(\mathrm{sin}\left(i\right),i=1..10\right)⟩⟩$
 ${A}{≔}\left[\begin{array}{cc}{1}& {\mathrm{sin}}{}\left({1}\right)\\ {2}& {\mathrm{sin}}{}\left({2}\right)\\ {3}& {\mathrm{sin}}{}\left({3}\right)\\ {4}& {\mathrm{sin}}{}\left({4}\right)\\ {5}& {\mathrm{sin}}{}\left({5}\right)\\ {6}& {\mathrm{sin}}{}\left({6}\right)\\ {7}& {\mathrm{sin}}{}\left({7}\right)\\ {8}& {\mathrm{sin}}{}\left({8}\right)\\ {9}& {\mathrm{sin}}{}\left({9}\right)\\ {10}& {\mathrm{sin}}{}\left({10}\right)\end{array}\right]$ (6)
 > $R≔\mathrm{Rank}\left(A\left[1..10,2\right]\right)$
 ${R}{≔}\left[\begin{array}{cccccccccc}{8}& {9}& {5}& {2}& {1}& {4}& {7}& {10}& {6}& {3}\end{array}\right]$ (7)
 > $B≔\mathrm{OrderByRank}\left(A,R\right)$
 ${B}{≔}\left[\begin{array}{cc}{5}& {\mathrm{sin}}{}\left({5}\right)\\ {4}& {\mathrm{sin}}{}\left({4}\right)\\ {10}& {\mathrm{sin}}{}\left({10}\right)\\ {6}& {\mathrm{sin}}{}\left({6}\right)\\ {3}& {\mathrm{sin}}{}\left({3}\right)\\ {9}& {\mathrm{sin}}{}\left({9}\right)\\ {7}& {\mathrm{sin}}{}\left({7}\right)\\ {1}& {\mathrm{sin}}{}\left({1}\right)\\ {2}& {\mathrm{sin}}{}\left({2}\right)\\ {8}& {\mathrm{sin}}{}\left({8}\right)\end{array}\right]$ (8)
 > $\mathrm{evalf}\left(B\right)$
 $\left[\begin{array}{cc}{5.}& {-0.9589242747}\\ {4.}& {-0.7568024953}\\ {10.}& {-0.5440211109}\\ {6.}& {-0.2794154982}\\ {3.}& {0.1411200081}\\ {9.}& {0.4121184852}\\ {7.}& {0.6569865987}\\ {1.}& {0.8414709848}\\ {2.}& {0.9092974268}\\ {8.}& {0.9893582466}\end{array}\right]$ (9)

Handling non-numeric data.

 > $A≔⟨1,4,3,4,5,\mathrm{undefined}⟩:$
 > $B≔⟨4,\mathrm{undefined},\mathrm{\infty }⟩:$
 > $C≔\left[a,b,c,a,b,a\right]:$

Join samples A, B, and C

 > $U≔\mathrm{Join}\left(\left[A,B,C\right]\right)$
 ${U}{≔}\left[\begin{array}{ccccccccccccccc}{1}& {4}& {3}& {4}& {5}& {\mathrm{undefined}}& {4}& {\mathrm{undefined}}& {\mathrm{\infty }}& {a}& {b}& {c}& {a}& {b}& {a}\end{array}\right]$ (10)

Remove non-numeric values (keep missing values).

 > $V≔\mathrm{RemoveNonNumeric}\left(U,\mathrm{exclude}=\mathrm{undefined}\right)$
 ${V}{≔}\left[\begin{array}{cccccccc}{1}& {4}& {3}& {4}& {5}& {\mathrm{undefined}}& {4}& {\mathrm{undefined}}\end{array}\right]$ (11)

Count total number of values and the number of missing values in V.

 > $\mathrm{Count}\left(V\right)$
 ${8}$ (12)
 > $\mathrm{CountMissing}\left(V\right)$
 ${2}$ (13)

The same using weights.

 > $W≔⟨\frac{1}{2},\frac{1}{3},\frac{1}{4},\frac{1}{5},\frac{1}{6},\frac{1}{7},\frac{1}{8},\frac{1}{9}⟩:$
 > $\mathrm{CountMissing}\left(V\right)$
 ${2}$ (14)
 > $\mathrm{CountMissing}\left(V,\mathrm{weights}=W\right)$
 ${0.253968253968254}$ (15)