aboutsummaryrefslogtreecommitdiff
path: root/bin/mode.awk
blob: beced1f44e735f79888d32a5b8d5a3727a088df7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
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
}