Quantcast
Channel: Count number in two columns and generate matrix? - Ask Ubuntu
Viewing all articles
Browse latest Browse all 2

Answer by steeldriver for Count number in two columns and generate matrix?

$
0
0

What you appear to want is called a cross tabulation or contingency table .

While it's certainly possible to implement a solution using generic tools such as awk, perl, or python, the easiest approach IMHO would be to install GNU datamash - you can then straightforwardly do

datamash --sort --whitespace --filler=0 crosstab 2,1 sum 3 < file

If there's only a single entry per pair (as appears to be the case in your example), then you can use unique in place of sum.

You can also do cross-tabulation in many spreadsheet applications - where it's often called pivot tables.


Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>