d3- Find max kay/value in nested arrays

d3- Find max kay/value in nested arrays

d3 nested data
d3 max
d3 get max
d3 max typescript
d3 max of multiple columns
d3 max dataset, function(d)

I have an array of 3 nested arrays, each containing 3 objects. What d3 syntax do I use to find the max value of data1 in all of the data?

Is it something like,

function find_max(all_data, i){
    return d3.max(all_data[i].data1)
}

Here's my data structure:

all_data = [
        [{data1:2, age:6},
         {data1:4, age:5},
         {data1:5, age:4}],

        [{data1:7, age:2},
         {data1:1, age:9},
         {data1:0, age:8}],

        [{data1:5, age:9},
         {data1:6, age:9},
         {data1:8, age:6}]
       ]

Basically, I want it to return 8. Thanks for the help!! I can't quite get it right.


We can use a mix of d3.max and Array.map operations:

d3.max(all_data.map(d => d3.max(d.map(n => n.data1)))) // 8

This finds the max of each nested array using d3.max to find the max and a map operation to transform nested arrays of objects into an array of data1 values ([2, 4, 5] for the first nested array).

[{data1:2, age:6}, {data1:4, age:5}, {data1:5, age:4}].map(n => n.data1) // [2, 4, 5]
d3.max([{data1:2, age:6}, {data1:4, age:5}, {data1:5, age:4}].map(n => n.data1)) // 5

And with each sub-max, we find the global max using d3.max again.

var all_data = [
  [{data1:2, age:6},
    {data1:4, age:5},
    {data1:5, age:4}],

  [{data1:7, age:2},
    {data1:1, age:9},
    {data1:0, age:8}],

  [{data1:5, age:9},
    {data1:6, age:9},
    {data1:8, age:6}]
];

console.log(d3.max(all_data.map(d => d3.max(d.map(n => n.data1)))));
<script src="https://d3js.org/d3.v5.min.js"></script>

Extent of extents · Issue #64 · d3/d3-array · GitHub, I propose to change d3.extent, d3.min, etc. to treat arrays differently (e.g. it's a common task to calculate extent of extents, and currently I see no The expectation is that you call d3.min and d3.max separately if you have nested arrays, such as: You'd by the value accessor to d3.min using d3.min.by:. # d3.max(iterable[, accessor]) · Source, Examples. Returns the maximum value in the given iterable using natural order. If the iterable contains no comparable values, returns undefined. An optional accessor function may be specified, which is equivalent to calling Array.from before computing the maximum value.


Probably the easiest way is to nest d3.max():

function findMax(data) {
  return d3.max(data, arr =>    // return max of all nested max values
    d3.max(arr, d => d.data1)   // return max of each nested array
  );
}

The outer call to d3.max() uses its accessor function to get access to the maximum value of each nested array. The inner call will determine the maximum value for each nested array. For this purpose it defines an accessor function to return the data1 property.

Have a look at the following working demo:

const all_data = [
        [{data1:2, age:6},
         {data1:4, age:5},
         {data1:5, age:4}],

        [{data1:7, age:2},
         {data1:1, age:9},
         {data1:0, age:8}],

        [{data1:5, age:9},
         {data1:6, age:9},
         {data1:8, age:6}]
       ];
       
function findMax(data) {
  return d3.max(data, arr =>
    d3.max(arr, d => d.data1)
  );
}

console.log(findMax(all_data));
<script src="https://d3js.org/d3.v5.js"></script>

Grouping Data, D3 includes the powerful d3.nest functionality to produce these groupings with a And that has been converted to a nice array of objects via our data reading powers Each object has a key property - which is what we used as the grouping value Here is another example where we get the average amount per person: The easiest way to work with D3 data arrays is to create simple arrays. For example, to create a stacked array, represent each stack in a stacked bar by the a comma separated value in a row per bar. state, males, females


You could map the inner data1 values and get the max value and then take the result for the outer array.

var all_data = [[{ data1: 2, age: 6 }, { data1: 4, age: 5 }, { data1: 5, age: 4 } ], [{ data1: 7, age: 2 }, { data1: 1, age: 9 }, { data1: 0, age: 8 }], [{ data1: 5, age: 9 }, { data1: 6, age: 9 }, { data1: 8, age: 6 }]],
    maxData1 = Math.max(...all_data.map(a => Math.max(...a.map(({ data1 }) => data1))));
    
console.log(maxData1);

Simplest/Cleanest way to implement singleton in JavaScript?, object immutable, preventing any modification to the its structure and values. 5183 | d3- Find max kay/value in nested arrays; 7318 | How to get ISO 3166-1  Related d3/d3#1964.. Currently, min and max return the minimum and maximum value from an array of elements, using an optional value accessor. In some cases, it might be nice to either return the minimum or maximum index of a given element, or the element itself.


[PDF] Basic Concepts in Matlab, Michael G. Kay. Fitts Dept. of kay@ncsu.edu. January 2017 In Matlab, the case of a variable matters; e.g., the arrays a and create an array by first generating an array of zeros at the command line create a function mydist.m to determine the Euclidean A logical array of 1 (true) and 0 (false) values is returned as a. # d3.extent(array[, accessor]) Returns the minimum and maximum value in the given array using natural order. This is equivalent to calling d3.min and d3.max simultaneously. # d3.sum(array[, accessor]) Returns the sum of the given array. If the array is empty, returns 0.


Excel functions list with formula examples, And here's an example of the nested IF formula that "deciphers" the exam It multiplies the supplied array components and returns the sum of the products. Excel functions to find the largest, smallest and average values at the intersection of the 3rd row and 4th column, which is cell D3. Kay says:. D3 Nest Tutorial and examples. Here is my learning process for getting to grips with nest. Discovered the d3 tests half way through which were a great help: tests. Simple one level nest. In Bl.ocks.org, click on "Open in a New Window" (bottom right) to view all the examples. Group by status. var nested_data = d3.nest().key(function(d) { return


Excel COUNTIF and COUNTIFS Formulas Explained • My Online , You'll find a huge range all explained in plain English, plus PivotTables Excel MIN MAX SMALL and LARGE Functions Use an Excel formula to extract values present in two lists of varying sizes. Reducing Data Validation List using Excel's dynamic array formulas Excel C3 – “Dave” Excel D3 – “10” Now we have nested data with branches and leaves at arbitrary depths! Underscore.burrow can take an an array of objects or an array of arrays. If you pass an array of objects, each object must contain a nodes property, whose value is an array of node items. Likewise, if you pass an array of arrays, each array must be a list of node items.