Comments (4)
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.
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.
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.
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)
- min, max, extent exhibit unexpected behavior for arrays of integers of differing numbers of digits HOT 1
- BUG: d3-array/dist/d3-array.js: Unexpected token (139:15) HOT 4
- fix(babel): cumsum HOT 1
- binary ticks increments on linear scale HOT 2
- D3-array produces ERR_REQUIRE_ESM with node >= 15 HOT 3
- bisectCenter naming HOT 1
- quantile returns undefined on an empty array, differs from extent HOT 1
- Docs: define the bin thresholds with array HOT 2
- First and last thresholds are set to data extent (not explicitly stated limits) HOT 2
- bisector no longer supports two-argument (object, value) comparator HOT 12
- Testing a lib using `d3-array` HOT 1
- d3.blur HOT 1
- Incorrect results for binary search on large arrays due to miscomputation of midpoint HOT 11
- d3.bin can mutate the user-specified thresholds
- About the sorting problem of d3.rank HOT 2
- Insecure Randomness for the useof Math.random() in shuffle API (security vulnerability) HOT 1
- d3.thresholdScott returns NaN for single-element arrays
- Feature request: `find` / `findValue` methods
- groupSort should use ascendingDefined instead of ascending
- medianIndex/quantileIndex doesn’t handle missing data HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from d3-array.