Post Reply 
Can the name of the MODE function be changed? (Statistics)
11-01-2017, 07:09 AM
Post: #6
RE: Can the name of the MODE function be changed? (Statistics)
(10-31-2017 11:39 PM)StephenG1CMZ Wrote:  However, I think there is a bug:
{1,2} yields {1,2,0} rather than the expected {1,2}.

Your version doesn't handle {"red","green","red} - but then it is likely much faster as well as more concise.

Ah, I've been too aggressive in the simplifications. Here is an updated version that should work better including for non numeric lists, but it's less concise...

Code:
EXPORT ModeList(L)
BEGIN
 LOCAL l1,l2;
 l1:=UNION(L);
 l2:=MAKELIST(SIZE(INTERSECT(L,l1(I))),I,1,SIZE(l1));
 l2:=(l2==MAX(l2))*MAKELIST(I,I,1,SIZE(l1));
 l2:=remove(0,l2);
 MAKELIST(l1(l2(I)),I,1,SIZE(l2));
END;
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Can the name of the MODE function be changed? (Statistics) - Didier Lachieze - 11-01-2017 07:09 AM



User(s) browsing this thread: 1 Guest(s)