Jump to content

Mode() custom function


This topic is 6870 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Here's a pair of custom functions to return the mode for a list of numbers. Example:

Given:

4

2

3

2

5

Returns: 2

This function requires the list to be in sorted order. I used Jeremy Bante's QuickSort() CF to do this.

Mode ( list ) =


//Mode ( list )

//Given a list of numbers, returns the value(s) that occur most often.

//7-25-2005

//By Mike Hackett

Let (

[

bimodalSeparator = ", "; //how you want tied values to be separated

valueCount = ValueCount( list );

sortedList = QuickSort ( list ); //sorts the values

resultList = LeftValues( sortedList; 1 ); //keeps track of the values that occur most ofter

resultCount = 1; //occurrence count for the listed results

currentValue = LeftValues (sortedList; 1); //current value being checked

currentCount = 1; //occurrence count for current value

result = Substitute (

ModeSub ( RightValues(sortedList; valueCount -1) ; "" ; 0; currentValue ; currentCount ); //initial call to recursive sub function

Mode.fp7.zip

Link to comment
Share on other sites

This topic is 6870 days old. Please don't post here. Open a new topic instead.

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.