Ender Posted July 25, 2005 Posted July 25, 2005 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
Recommended Posts
This topic is 7061 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 accountSign in
Already have an account? Sign in here.
Sign In Now