As a useful extension of this question:
Elegant operations on matrix rows and columns
I would like to ask:
What are for you elegant, short, useful or frequently used functions to use with associations or datasets?
I propose to distinguish between
- Simple associations
- Associations with named columns and rows
- Associations with named columns
- Datasets
Some examples for each of these four categories follow:
1. Simple associations
aset = <|"A" -> 10., "B" -> 20., "C" -> 30., "D" -> 40.|>;
MovingAverage was recently changed to also work with associations (undocumented):
MovingAverage[aset, 2]
<|"B" -> 15., "C" -> 25., "D" -> 35.|>
2. Associations of associations
mset =
<|"10" -> <|"A" -> 10., "B" -> 20., "C" -> 30., "D" -> 40.|>,
"20" -> <|"A" -> 50., "B" -> 60., "C" -> 70., "D" -> 80.|>,
"30" -> <|"A" -> 90., "B" -> 100., "C" -> 110., "D" -> 120.|>,
"40" -> <|"A" -> 130., "B" -> 140., "C" -> 150., "D" -> 160.|>,
"50" -> <|"A" -> 170., "B" -> 180., "C" -> 190., "D" -> 200.|>|>;
Transpose
mset // Query[Transpose] // Dataset
Add column total
Query[<|#, "Total" -> Total[#]|> &] @ mset // Dataset
Extract
Query[{"10", "20"}, {"A", "B"}] @ mset // Dataset
3. Associations with named columns
JoinAcross
cset = Values @ mset;
join = {<|"A" -> 10., "E" -> "Red"|>, <|"A" -> 90., "E" -> "Blue"|>};
JoinAcross[cset, join, "A", "Left"] // SortBy["A"] // Dataset
4. Dataset
Display as BarChart
dset = Dataset[mset];
dset[BarChart[#, ChartLabels -> Automatic] &]




