Published unlisted
Edited
Aug 17, 2022
Insert cell
Insert cell
penguins
Insert cell
withTotal = {
let numericKeys = Object.entries(penguins[0])
.filter(([key, value]) => typeof value === "number")
.map((d) => d[0]);
let sumRow = Object.fromEntries(
numericKeys.map((key) => [key, d3.sum(penguins, (d) => d[key])])
);
sumRow.species = "Sum";
let meanRow = Object.fromEntries(
numericKeys.map((key) => [key, d3.mean(penguins, (d) => d[key])])
);
meanRow.species = "Mean";
return [sumRow, meanRow, ...penguins];
}
Insert cell
Inputs.table(withTotal)
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