Seeking guidance as I navigate through the world of javascript and D3.js.
I have two distinct data sets (arrays of objects) that I hope to merge. My goal is to align the National Average Scores with the State Average Scores by matching the 'Answer' field. To explore the data, feel free to copy and paste this into Tributary.
// National Averages Data Set
var nationaldataset = [];
var nAvg = "http://data.medicare.gov/resource/89u8-shx4.csv";
var nscore = "HCAHPS Answer Percent";
var nquestion = "HCAHPS Question";
var nanswer = "HCAHPS Answer Description";
d3.csv( nAvg, function(data) {
nationaldataset = data.map(function(d) { return [ d[nquestion], d[nanswer], d[nscore] ]; });
d3.select("body").selectAll("p")
.data(nationaldataset)
.enter()
.append("p")
.text( function(d) {return d ;} );
});
// State Averages Data Set
var statedataset = [];
var sAvg = "http://data.medicare.gov/resource/fhk8-g4vc.csv"; //State Average
var sq1 = "Percent of patients who reported that their nurses \"Sometimes\" or \"Never\" communicated well."
var sq2 = "Percent of patients who reported that their nurses \"Usually\" communicated well."
var sq3 = "Percent of patients who reported that their nurses \"Always\" communicated well."
// .. this list continues for 30 columns
d3.csv( sAvg, function(data) {
sstatedataset = data.map(function(d) { return [ d["State"], d[sq1], d[sq2], d[sq3] ]; });
d3.select("body").selectAll("p")
.data(statedataset)
.enter()
.append("p")
.text(function(d) {return d ;} );
});
Despite researching various javascript array methods like Join(), Concatenate(), I still find myself stuck. How can I achieve a task similar to this -
Select nationaldataset.nquestion
, nationaldataset.nanswer
, nationaldataset.nscore
, statedataset.Score
From nationaldataset, statedataset
WHERE nationaldatset.nanswer = statedataset.columnname
AND statedataset.State in ['SD', 'MN', 'IA']