Skip to content

Instantly share code, notes, and snippets.

@krishnanraman
Last active August 29, 2015 13:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnanraman/8700534 to your computer and use it in GitHub Desktop.
Save krishnanraman/8700534 to your computer and use it in GitHub Desktop.
case "qualitative" =>
val sorted = rows
.groupBy(x=>x)
.map { xy => (xy._1, xy._2.size) }
.toList
.sortBy(x=>x._2)
.reverse
val py = sorted.head._2
val px = rows.distinct.map(w => w.length).max
sorted.map { i=>
(i._1, i._2, (i._2 * 60.0/py).toInt)
}
.foreach { i=>
printf( "%"+px+"s: %s\t%d\n", i._1, List.fill[Char](i._3)('#').mkString(""), i._2)
}
Here are some of the histograms generated by the code above -
Column: "Gun in Home"
$ scala GSSJob GSS-Data-for-Statwing-Prize.txt histo "Gun in Home" qualitative
No: ############################################################ 13607
Yes: ######################################## 9207
Column: "Sex Frequency"
$ scala GSSJob GSS-Data-for-Statwing-Prize.txt histo "Sex Freq" qualitative
Not at All: ############################################################ 4270
2-3 Per Week: ######################################################### 4070
Weekly: ################################################## 3593
2-3 Times a Month: ############################################### 3361
Once a Month: ############################### 2217
Once or Twice: ######################## 1714
4+ Per Week: ################### 1367
Column: "Age"
$ scala GSSJob GSS-Data-for-Statwing-Prize.txt histo "Age" quantitative
[18.0 - 25.1]: ################################################ 4826
[25.1 - 32.2]: ############################################################ 5979
[32.2 - 39.3]: ########################################################### 5913
[39.3 - 46.4]: ##################################################### 5315
[46.4 - 53.5]: ################################################ 4816
[53.5 - 60.6]: ####################################### 3929
[60.6 - 67.7]: ################################ 3273
[67.7 - 74.8]: ########################## 2635
[74.8 - 81.9]: ################# 1773
[81.9 - 89.0]: ########## 1075
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment