compute aggregate statistics on a DataFrame
Aggregate( data, bycolumn, options )
name, string, or integer; gives the column of the DataFrame used to split the data set into subsets
(optional) equation(s) of the form option=value where option can be any of bounds, columns, function or tally.
bounds : By default, Aggregate uses the SplitByColumn command to creates a separate sub-DataFrame for every discrete level in the column given by bycolumn. If the data in the bycolumn column is more or less continuous, the bounds option can be used to specify boundaries of bins into which values are collected. There are several different ways to use this option:
bounds = none is the default and leads to a separate bin for every value in the key column.
bounds = [b0, b1, ..., bn] means values from the key column will be divided into n bins: from b0 to b1, from b1 to b2, etc. Values less than b0 or greater than bn, and the rows containing them, are discarded.
bounds = quantiles(q0, q1, ..., qn) or bounds = deciles(d0, d1, ..., dn) or bounds = percentiles(p0, p1, ..., pn) or bounds = quartiles(q0, q1, ..., qn) are equivalent ways of specifying bins similar to specifying a list, but instead of specifying absolute numbers for the bounds, you specify which fraction of the data should fall in each of the bins. For example, specifying bounds = percentiles(0, 25, 60, 90) specifies three bins, the first of which contains the lowest 25% of data, then then next 60% - 25% = 35% of data, and finally the following 90% - 60% = 30% of data. That is, the bounds are at the 0th, 25th, 60th, and 90th percentile of the data in the key column. This could also be specified as bounds = quantiles(0, 0.25, 0.6, 0.9) using the notion of Quantile instead of Percentile, or bounds = deciles(0, 2.5, 6, 9) using Deciles, or bounds = quartile(0, 1, 2.4, 3.6) using Quartiles.
columns : list; list of numeric values corresponding to the columns or column names. The default is to show all columns.
function : procedure or list(procedure,options); controls the summary statistic or procedure that is applied to the subsets of data. The default is Statistics:-Mean. If function is given as a list, the first element corresponds to the command used to compute the aggregate statistic, and any additional arguments are passed to the given command.
tally : truefalse; controls the display of an additional column in the aggregate DataFrame containing tallies for each level for the given option ByColumn. The default is false.
The Aggregate command returns aggregate statistics on a DataFrame for each distinct level (factor) in a given column.
Aggregate statistics are calculated by splitting the rows of a DataFrame by each factor in a given column into subsets and computing summary statistics for each of the subsets of data.
The output from the Aggregate command is a DataFrame that contains only one row per factor in the given column along with the requested summary statistic for each respective other column.
DF ≔ DataFrame⁡1,1,2,2,2,3|5,3,6,2,1,4|6,5,1,4,9,9|4,2,1,7,8,3,columns=ID,X1,X2,X3
The following returns the mean of all other columns for each distinct level in the column, ID.
Adding the columns option controls which columns are returned. Additionally, the tally option returns a tally for each of the factors.
The function option allows for the specification of any command that can be applied to a DataSeries. For example, the Statistics:-Median command computes the median for each of the factors of ID.
The Append command appends a column on the right side of the original DataFrame.
If the function option is given as a list, supplementary arguments can be passed to the applied command.
The bounds option makes it possible to customize the bins used for the aggregate statistics. In the following, values for the ID column between 1 and 2 are put into the first bin and values 2 and above are put into another.
The DataFrame/Aggregate command was introduced in Maple 2016.
For more information on Maple 2016 changes, see Updates in Maple 2016.
Download Help Document
What kind of issue would you like to report? (Optional)