Public
Edited
Oct 24, 2023
Fork of d3.sum
3 forks
37 stars
Insert cell
Insert cell
numbers = [83, 32, 14, 52, 31, 66, 12, 11, 0, 78, 60, 97, 47, 37, 91, 58, 48, 55, 98, 45, 64, 1, 17, 39, 82, 24, 5, 40, 61, 27, 57, 34, 56, 26, 30, 36, 43, 80, 85, 68, 75, 50, 59, 44, 18, 19, 88, 87, 41, 90, 4, 81, 94, 89, 93, 22, 3, 67, 13, 35, 96, 16, 7, 15, 20, 76, 63, 49, 25, "95", 86, 99, 28, 62, 71, undefined, 21, 10, 72, 29, 51, 46, 73, 74, 9, 65, 77, 92, 6, 8, 2, 79, 53, 69, 70, 33, 54, 42, 23, 84, 38, NaN, "Fred"]
Insert cell
d3.mean(numbers)
Insert cell
Insert cell
d3.sum(numbers) / d3.count(numbers)
Insert cell
Insert cell
numbers.filter(d => d !== +d)
Insert cell
Insert cell
numbers.length - d3.count(numbers) // The number of missing values!
Insert cell
Insert cell
olympians
Insert cell
Insert cell
d3.mean(olympians, d => d.height)
Insert cell
d3.median(olympians, d => d.height)
Insert cell
Insert cell
{
const now = Date.now();
const year = 1000 * 60 * 60 * 24 * 365.25;
return d3.mean(olympians, d => (now - d.date_of_birth) / year);
}
Insert cell
Insert cell
d3.mean(olympians.filter(d => d.sport === "basketball"), d => d.height)
Insert cell
d3.mean(olympians, d => d.sport === "basketball" ? d.height : NaN)
Insert cell
Insert cell
Insert cell
d3.median([0, 1, 5])
Insert cell
d3.median([0, 1, 2, 5])
Insert cell
Insert cell
d3.variance(olympians, d => d.height)
Insert cell
d3.deviation(olympians, d => d.height)
Insert cell
Insert cell
Insert cell
Insert cell
d3.quantile(olympians, 0.05, d => d.height)
Insert cell
d3.quantile(olympians, 0.95, d => d.height)
Insert cell
Insert cell
sortedHeights = olympians
.map(d => d.height)
.filter(d => d !== null && !isNaN(d))
.sort(d3.ascending)
Insert cell
d3.quantileSorted(sortedHeights, 0.05)
Insert cell
d3.quantileSorted(sortedHeights, 0.95)
Insert cell
Insert cell
Insert cell
d3.deviation(Float32Array.from({length: 1000}, Math.random))
Insert cell
d3.sum(new Set([1, 2, 3]))
Insert cell
d3.quantile(Float64Array.from({length: 1000}, Math.random), 0.1)
Insert cell
Insert cell
Insert cell
frenchteam = olympians.filter(d => d.sport === "handball" && d.sex === "female" && d.nationality == "FRA")
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more