After removing duplicate rows from my dataset using a d3.nest() function, I now have unique entries in my JSON array. My goal is to calculate the mean 'cycle time' for each date. The desired output should resemble:
[
{
"key": "2012-03",
"values": [
{
"mean": 16,
}
]
},
{
"key": "2012-06",
"values": [
{
"mean": 10,
}
]
},
{
"key": "2012-07",
"values": [
{
"mean": 8,
}
]
}
]
I've attempted to follow online examples but it seems like I might be missing something obvious. Can someone please assist?
var summaryTable = [
{
"key": "2012-03",
"values": [
{
"key": "AAA-1",
"value": {
"cycletime": 14
}
},
{
"key": "AAA-2",
"value": {
"cycletime": 18
}
}
]
},
{
"key": "2012-06",
"values": [
{
"key": "AAA-3",
"value": {
"cycletime": 8
}
},
{
"key": "AAA-4",
"value": {
"cycletime": 12
}
}
]
},
{
"key": "2012-07",
"values": [
{
"key": "AAA-5",
"value": {
"cycletime": 15
}
},
{
"key": "AAA-5",
"value": {
"cycletime": 1
}
},
{
"key": "AAA-6",
"value": {
"cycletime": 8
}
}
]
}
]
var d3Table = d3.nest()
.key(function(d) { return d['key']; })
.rollup(function(d) {
return {
"medianCycleTime": d3.mean(d, d3.values(d['values']['value'])),
};
})
.entries(summaryTable);