Public
Edited
Jan 22, 2023
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
results = d3.flatRollup(
data,
v => calculateStatistics(v, d => d.a),
d => d.a < 0.5 ? "X" : "Y",
d => d.b < 0.3 ? "X" : "Y"
).map(([a, b, stats]) => ({ a, b, ...stats }))
Insert cell
function calculateStatistics(iterable, reduce) {
// const stats = ["count", "max", "min", "mean", "mode"];
// return Object.fromEntries(stats.map(d => [d, d3[d](iterable, reduce)]));
return {
count: d3.count(iterable, reduce),
max: d3.max(iterable, reduce),
min: d3.min(iterable, reduce),
mean: d3.mean(iterable, reduce),
q90: d3.quantile(iterable.map(reduce), 0.9)
}
}
Insert cell
results
Type Table, then Shift-Enter. Ctrl-space for more options.

Insert cell
Type JavaScript, then Shift-Enter. Ctrl-space for more options. Arrow ↑/↓ to switch modes.

Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more