mirror of
https://github.com/johnkerl/miller.git
synced 2026-07-19 09:24:14 +00:00
24 lines
512 B
Bash
24 lines
512 B
Bash
mlr --from data/medium put -q '
|
|
# Using the y field for weighting in this example
|
|
weight = $y;
|
|
|
|
# Using the a field for weighted aggregation in this example
|
|
@sumwx[$a] += weight * $i;
|
|
@sumw[$a] += weight;
|
|
|
|
@sumx[$a] += $i;
|
|
@sumn[$a] += 1;
|
|
|
|
end {
|
|
map wmean = {};
|
|
map mean = {};
|
|
for (a in @sumwx) {
|
|
wmean[a] = @sumwx[a] / @sumw[a]
|
|
}
|
|
for (a in @sumx) {
|
|
mean[a] = @sumx[a] / @sumn[a]
|
|
}
|
|
#emit wmean, "a";
|
|
#emit mean, "a";
|
|
emit (wmean, mean), "a";
|
|
}'
|