Mode
samplescreenshot.gif

Routine Summary

Calculates the mode(s) of a list of numbers.

Inputs

Str1 - To store the user-inputted list of numbers

Outputs

LM6 - The mode(s) of the original list of numbers

Variables Used

The variables used in the routine.

List the variables one after another, separating each with a comma.

Calculator Compatibility

TI-83/84/+/SE/CSE/CE

Author

Calcblog, modified slightly by Myles_Zadok

Authors

{$authors}

URL: [{$url}]

Download

[{$download}]

:ClrHome
:Input "DATA AS LIST:",Str1
:expr("{"+Str1→⌊M
:1→A
:Lbl A
:⌊M(A)=⌊M→⌊M2
:sum(⌊M2)→⌊M3(A):If A<dim(⌊M):Then:A+1→A:Goto A:End
:⌊M→⌊M6
:If sum(⌊M3-1)=0:Then
:Disp "NO MODE!"
:Goto F
:End
:SortD(⌊M3,⌊M6)
:1→A
:1→B
:While ⌊M3(A)=max(⌊M3):⌊M6(A)→⌊M5(B):B+1→B:A+1→A:End
:1→A
:2→B
:ClrList ⌊M6
:SortA(⌊M5
:⌊M5(dim(⌊M5))→⌊M6(1)
:Lbl C
:If A≥(dim(⌊M5)-1):Then:Goto E:End
:If A<(dim(⌊M5)-1):Then
:If ⌊M5(A)≠⌊M5(A+1):Then:⌊M5(A)→⌊M6(B):B+1→B:A+1→A:Goto C:End
:If ⌊M5(A)=⌊M5(A+1):Then:A+1→A:Goto C:End
:Lbl E
:SortA(⌊M6
:Disp ⌊M6
:Lbl F
:ClrList ⌊M2,⌊M3,⌊M4,⌊M5,⌊M6

The mode of a list is the value that occurs most often within the list. This routine will find the mode and, if there are any ties, will display all modes. Examples:

:{1,2,3,3,4
Mode = {3}
:{5,5,6,6,7
Mode = {5,6}

.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-Noncommercial-No Derivative Works 2.5 License.