Sign in to follow this  
Followers 0
Gabs

Calculate the most frequent value from a set of data

2 posts in this topic

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 this post


Link to post
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)

Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0