Sunday, 15 February 2015

d3.js - How to merge 2 tsv files, based on a common value (in javascript) -



d3.js - How to merge 2 tsv files, based on a common value (in javascript) -

i have 2 tsv files (tec00104.tsv & tec00114.tsv), info countries. want create 1 single array mutual countries both tsv files. , values comes along. doesn't seem work, why?

// initialize array var countries = []; for(var = 0; < "tec00114.tsv".length; i++) { for(var j = 0; j < "tec00104.tsv".length; j++) { // if country code found in both tsv files if("tec00114.tsv"[i][2] === "tec00104.tsv"[j][3]); { // append new value array countries.push("tec00114.tsv"[i]); countries.push("tec00104.tsv"[j]); } } } console.log(countries);

the problem, trying refer filenames straight javascript array. impossible in way. need load them before (e.g. can $.get() function).

or can alasql library.

<script src="alasql.min.js"></script> <script> var countries = alasql('select t1.*, t2.* tsv("tec00114.tsv") t1 \ bring together tsv("tec00104.tsv") t2 on t1.[2] = t2.[3]'); </script>

if tsv file has headers, utilize "headers:true" option, below:

select * tsv("tex00114.tsv", {headers:true});

javascript d3.js tsv

No comments:

Post a Comment