Skip to content

medianIndex/quantileIndex doesn’t handle missing data #275

@mbostock

Description

@mbostock

d3.medianIndex returns one less than the index of the median element. For example:

penguins[d3.medianIndex(penguins, (d) => d.body_mass_g)].body_mass_g // 3600
penguins[d3.medianIndex(penguins, (d) => d.body_mass_g) + 1].body_mass_g // 4050

I don’t think this is the intended behavior, even if we were trying to chose the “lower” element in the case where the array length is even. I expect it to return the index of the median value instead.

d3.median(penguins, (d) => d.body_mass_g) // 4050

Previously #140 #159.

Metadata

Metadata

Assignees

Labels

bugSomething isn’t working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions