I am doing D3 mapping on a state level. Here one problem that i met in data processing. For example, map data are like this, (dat1.ndjson)
{state: a, code: aa}
{state: b, code: bb}
{state: c, code: cc}
But usually the information we have are not complete, for example, there are no information in Antarctica usually but we still need to draw its contour when we do mapping. Information data is like, (dat2.ndjson)
{state: a, code: aa, count: 1}
{state: b, code: bb, count: 2}
So, when i try to do left join on these two data, it will returns (dat3.ndjson)
[{state: a, code: aa},{state: a, code: aa, count: 1}]
[{state: b, code: bb},{state: b, code: bb, count: 2}]
[{state: c, code: cc},null]
This is returned by
ndjson-join --left 'd.code' dat1.ndjson dat2.ndjson < merge.ndjson
The purpose is to connect this 'count' information to map data, so usually I will first assign all items a count = 0 in dat1.ndjson, like this, (dat11.ndjson)
{state: a, code: aa, count: 0}
{state: b, code: bb, count: 0}
{state: c, code: cc, count: 0}
and then use this left join method like the one I showed before to get something like this, (dat33.ndjson)
[{state: a, code: aa, count: 0},{state: a, code: aa, count: 1}]
[{state: b, code: bb, count: 0},{state: b, code: bb, count: 2}]
[{state: c, code: cc, count: 0},null]
But here comes the problem. If i use the following command to add all values together, it will return an error because of that null in the third line.
ndjson-map '{state: d[0].state, code: d[0].code, count: d[0].count +
d[1].count}' < dat33.ndjson > merge.ndjson
Now I have to do this data processing in R which takes a lot of time as I need to do transformation between .ndjson and .csv. So I am looking for a better way to do this. I think there might be some ways by using 'ndjson-cli', 'jq' or 'awk' and 'sed' and etc.
Anyone have ideas? Thank you! :)
E.