Created
November 28, 2018 17:02
-
-
Save sabha/40faa1b9297792fc00e9a50368fee104 to your computer and use it in GitHub Desktop.
Stats Frequency
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//var data = ['A', 'O', 'A', 'B', 'B', 'AB', 'B', 'B', 'O', 'A', 'O', 'O', 'O', 'AB', 'B', 'AB', 'AB', 'A', 'O', 'A']; | |
var data = ['A', 'O', 'A','A','A','A', 'A','A','A','A', 'A','A','A','A', 'A','A','A','A', 'A','A','A','A']; | |
var count = {} | |
data.forEach((d) => { | |
count[d] = ((count[d] === undefined) ? 1 : (count[d]+1)); | |
}); | |
var addAll = (accumulator, currentValue) => accumulator + currentValue; | |
var len = Object.keys(count).map((r) => count[r]).reduce(addAll); | |
Object.keys(count).map((r) => { | |
console.log((count[r]/len)*100); | |
return ({'#': r, '%': (count[r]/len)*100}) | |
}); | |
//95.45454545454545 | |
//4.545454545454546 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://www.statisticshowto.datasciencecentral.com/how-to-make-a-frequency-chart-and-determine-frequency/