Skip to main content
added 258 characters in body
Source Link
kjo
  • 11.8k
  • 1
  • 33
  • 91

Given a simple dataset like this one:

Mathematica graphics

...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

Mathematica graphics

For MinMax it would be

Mathematica graphics

&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]]
]

Given a simple dataset like this one:

Mathematica graphics

...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

Mathematica graphics

For MinMax it would be

Mathematica graphics

&c.


NB: 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]]
]

Given a simple dataset like this one:

Mathematica graphics

...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

Mathematica graphics

For MinMax it would be

Mathematica graphics

&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]]
]
Source Link
kjo
  • 11.8k
  • 1
  • 33
  • 91

How to reduce each column of a dataset?

Given a simple dataset like this one:

Mathematica graphics

...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

Mathematica graphics

For MinMax it would be

Mathematica graphics

&c.


NB: 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]]
]