The same methods that are available for aggregating over
the columns of data frames are also available for vectors and matrices.
Aggregating over matrices
For matrices, it is possible to aggregate over both the rows and
columns. The
AggregateRows
method aggregates the rows of a matrix into a single vector or, when multiple
aggregators have been supplied, a matrix.
The AggregateRowsBy
method aggregates groups within each row.
In the following example, we create a matrix of random numbers and compute
the means of its rows. We then create a moving window of length 5,
and construct a matrix that contains the moving average of each row:
var m1 = Matrix.CreateRandom(10, 100);
var rowMeans = m1.AggregateRows(Aggregators.Mean);
var window = Grouping.Window(m1.ColumnCount, 5);
var rowMAs = m1.AggregateRowsBy(window, Aggregators.Mean);
Dim m1 = Matrix.CreateRandom(10, 100)
Dim rowMeans = m1.AggregateRows(Aggregators.Mean)
Dim window = Grouping.Window(m1.ColumnCount, 5)
Dim rowMAs = m1.AggregateRowsBy(window, Aggregators.Mean)
No code example is currently available or this language may not be supported.
let m1 = Matrix.CreateRandom(10, 100)
let rowMeans = m1.AggregateRows(Aggregators.Mean)
let window = Grouping.Window(m1.ColumnCount, 5)
let rowMAs = m1.AggregateRowsBy<float>(window, Aggregators.Mean)
The
AggregateColumns
method aggregates the columns of a matrix into a single vector or, when multiple
aggregators have been supplied, a matrix.
The AggregateColumnsBy
method aggregates groups within each column.
The same example as above, but aggregating over columns instead of rows, becomes:
var m2 = Matrix.CreateRandom(100, 10);
var columnMeans = m2.AggregateColumns(Aggregators.Mean);
window = Grouping.Window(m2.RowCount, 5);
var columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean);
Dim m2 = Matrix.CreateRandom(100, 10)
Dim columnMeans = m2.AggregateColumns(Aggregators.Mean)
window = Grouping.Window(m2.RowCount, 5)
Dim columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)
No code example is currently available or this language may not be supported.
let m2 = Matrix.CreateRandom(100, 10)
let columnMeans = m2.AggregateColumns(Aggregators.Mean)
let window = Grouping.Window(m2.RowCount, 5)
let columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)
There is one more method for aggregating over columns:
AggregateColumnsListwiseU.
This method is the same as the regular
AggregateColumns.
method with the following exception: whenever a row contains a missing value,
the entire row is treated as missing. This effectively means that
the aggregation is performed after first performing listwise deletion of rows
with missing values. In the next example, we first set some missing values
and then compute the listwise column means of the matrix:
var m2 = Matrix.CreateRandom(100, 10);
var columnMeans = m2.AggregateColumns(Aggregators.Mean);
window = Grouping.Window(m2.RowCount, 5);
var columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean);
Dim m2 = Matrix.CreateRandom(100, 10)
Dim columnMeans = m2.AggregateColumns(Aggregators.Mean)
window = Grouping.Window(m2.RowCount, 5)
Dim columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)
No code example is currently available or this language may not be supported.
let m2 = Matrix.CreateRandom(100, 10)
let columnMeans = m2.AggregateColumns(Aggregators.Mean)
let window = Grouping.Window(m2.RowCount, 5)
let columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)
Similarly, vectors have
Aggregate
and
AggregateBy
methods that aggregate over the entire vector or each group, respectively.
In the next example, we create a vector of random values and compute its kurtosis.
We then compute the kurtosis of each chunk of length 10:
var v = Vector.CreateRandom(100);
var K = v.Aggregate(Aggregators.Kurtosis);
var partition = Grouping.Partition(v.Length, 10);
var Ks = v.AggregateBy(partition, Aggregators.Kurtosis);
Dim v = Vector.CreateRandom(100)
Dim K = v.Aggregate(Aggregators.Kurtosis)
Dim partition = Grouping.Partition(v.Length, 10)
Dim Ks = v.AggregateBy(partition, Aggregators.Kurtosis)
No code example is currently available or this language may not be supported.
let v = Vector.CreateRandom(100)
let K = v.Aggregate(Aggregators.Kurtosis)
let partition = Grouping.Partition(v.Length, 10)
let Ks = v.AggregateBy(partition, Aggregators.Kurtosis)
The
AggregateColumns
method aggregates the columns of a matrix into a single vector or, when multiple
aggregators have been supplied, a matrix.
The AggregateColumnsBy
method aggregates groups within each column.
The same example as above, but aggregating over columns instead of rows, becomes:
var m2 = Matrix.CreateRandom(100, 10);
var columnMeans = m2.AggregateColumns(Aggregators.Mean);
window = Grouping.Window(m2.RowCount, 5);
var columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean);
Dim m2 = Matrix.CreateRandom(100, 10)
Dim columnMeans = m2.AggregateColumns(Aggregators.Mean)
window = Grouping.Window(m2.RowCount, 5)
Dim columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)
No code example is currently available or this language may not be supported.
let m2 = Matrix.CreateRandom(100, 10)
let columnMeans = m2.AggregateColumns(Aggregators.Mean)
let window = Grouping.Window(m2.RowCount, 5)
let columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)
There is one more method for aggregating over columns:
AggregateColumnsListwiseU.
This method is the same as the regular
AggregateColumns.
method with the following exception: whenever a row contains a missing value,
the entire row is treated as missing. This effectively means that
the aggregation is performed after first performing listwise deletion of rows
with missing values. In the next example, we first set some missing values
and then compute the listwise column means of the matrix:
var m2 = Matrix.CreateRandom(100, 10);
var columnMeans = m2.AggregateColumns(Aggregators.Mean);
window = Grouping.Window(m2.RowCount, 5);
var columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean);
Dim m2 = Matrix.CreateRandom(100, 10)
Dim columnMeans = m2.AggregateColumns(Aggregators.Mean)
window = Grouping.Window(m2.RowCount, 5)
Dim columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)
No code example is currently available or this language may not be supported.
let m2 = Matrix.CreateRandom(100, 10)
let columnMeans = m2.AggregateColumns(Aggregators.Mean)
let window = Grouping.Window(m2.RowCount, 5)
let columnMAs = m2.AggregateColumnsBy(window, Aggregators.Mean)