Given a simple dataset like this one:
...I want to apply some reduction function (like Total
or MinMax
) to each column separately, so that the result would be a one-row dataset, with the same number and names of columns as in the original dataset.
For example, if the reduction function were Total
, the desired result would be
For MinMax
it would be
&c.
Does the built-in Dataset
functionality directly support this type of operation? Or does one have to unpack the Dataset
, apply the reductions to the columns in the underlying data, and stuff the results in a new Dataset
?
NB: If the former is the case, I'm looking for more than an incantation here. I want also to understand how the proposed solution follows from the Dataset
syntax given in the documentation.
FWIW, the code I used to create the data
dataset is given below.
data = Module[
{
numberOfRows = 8
, columnNames = {"A", "B", "C", "D", "E"}
, makeColumn
}
, SeedRandom[0]
; makeColumn[] := RandomReal[{0, 1}, numberOfRows]
; Dataset[Transpose[Association[# -> makeColumn[] & /@ columnNames], AllowedHeads -> All]]
]
data[All,Total]
? $\endgroup$Transpose
- posted as answer below. $\endgroup$