Coder Social home page Coder Social logo

Median of string values about d3-array HOT 4 CLOSED

d3 avatar d3 commented on May 1, 2024
Median of string values

from d3-array.

Comments (4)

mbostock avatar mbostock commented on May 1, 2024 1

These methods could use a little overhaul, yes.

First, d3.median and d3.quantile should use quickselect #74 rather than the former sorting (slow) and the latter requiring sorting (tedious and/or slow). (We could maybe still provide methods for pre-sorted input as an optimization, such as d3.medianSorted and d3.quantileSorted.)

Second, we should have separate methods for ordinal versus quantitative quantiles (e.g., strings versus numbers); the former of which cannot be interpolated and so the R-7 method isn’t appropriate.

from d3-array.

domoritz avatar domoritz commented on May 1, 2024

I see that this trickles down to quantile, which also does not support strings. I can see median of strings be tricky when there is no clear center as you have to decide on one.

Maybe the cleaner way is to just ask people to write the code themselves

a = ['a', 'b', 'c'];
a.sort()[Math.floor(a.length/2)]

from d3-array.

Fil avatar Fil commented on May 1, 2024

This issue isn't solved I'm afraid.

d3.median(['a', 'b', 'c']) is undefined and we provide no alternative method to find its real value.

Or do we want to promote @domoritz 's solution

from d3-array.

mbostock avatar mbostock commented on May 1, 2024

d3.median takes numbers, so it’s expected that it’ll return undefined if you don’t pass it any numbers. It says exactly that in the README:

Returns the median of the given iterable of numbers using the R-7 method. If the iterable contains no numbers, returns undefined. An optional accessor function may be specified, which is equivalent to calling Array.from before computing the median. This method ignores undefined and NaN values; this is useful for ignoring missing data.

from d3-array.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.