aboutsummaryrefslogtreecommitdiff
path: root/bin/mode.awk
diff options
context:
space:
mode:
Diffstat (limited to 'bin/mode.awk')
-rw-r--r--bin/mode.awk13
1 files changed, 13 insertions, 0 deletions
diff --git a/bin/mode.awk b/bin/mode.awk
new file mode 100644
index 00000000..beced1f4
--- /dev/null
+++ b/bin/mode.awk
@@ -0,0 +1,13 @@
+# Get mode of a list of integers
+# If the distribution is multimodal, the first mode is used
+{ vals[$1]++ }
+END {
+ # Error out if we read no values at all
+ if (!NR)
+ exit(1)
+ mode = vals[0]
+ for (val in vals)
+ if (vals[val] > vals[mode])
+ mode = val
+ printf "%u\n", mode
+}