# Calculate the most frequent value from a set of data

## Recommended Posts

The situation is this: i have, lets say, 50 different variables each containing a value. I would like to find out which one of these 50 values that is the most frequent one. I cant find it in the help file so im kinda stuck.

Example values:

1,2,3,3,3,4,4,5,6,7,8,8,8,8,8,8,8,8,9

Here there is most 8:s so 8 is the most frequent value but how do i calculate this in a program?

##### Share on other sites

.... but how do i calculate this in a program?

this will build an Array with all values and the number of occurences, then sort and display it...

```#include<array.au3>
\$input = "1,2,3,3,3,4,4,5,6,7,8,8,8,8,8,8,8,8,9"
\$a_Values = StringSplit(\$input, ",")
Dim \$a_Count[1][2]
For \$x = 1 To \$a_Values[0]
\$found = 0
For \$y = 1 To UBound(\$a_Count, 1) - 1
If \$a_Values[\$x] = \$a_Count[\$y][0] Then
\$a_Count[\$y][1] = \$a_Count[\$y][1] + 1
\$found = 1
EndIf
Next
If \$found = 0 Then
ReDim \$a_Count[\$y + 1][2]
\$a_Count[\$y][0] = \$a_Values[\$x]
\$a_Count[\$y][1] = 1
EndIf
Next
;Sort result
_ArraySort(\$a_Count, 1, 1, 0, 2, 1)
;display result
\$msg = ""
For \$y = 1 To UBound(\$a_Count, 1) - 1
\$msg = \$msg & "Value:" & \$a_Count[\$y][0] & "  occured:" & \$a_Count[\$y][1] & @LF
Next
MsgBox(0, "result", \$msg)```

Live for the present,
Dream of the future,
Learn from the past.

## Create an account

Register a new account