Path: utzoo!utgpu!water!ljdickey From: ljdickey@water.waterloo.edu (Lee Dickey) Newsgroups: comp.lang.apl Subject: MODE Keywords: mode Message-ID: <1428@water.waterloo.edu> Date: 24 Feb 88 14:30:19 GMT Reply-To: ljdickey@water.waterloo.edu (Lee Dickey) Organization: U. of Waterloo, Ontario Lines: 26 A few weeks ago someone posted an article asking about an efficient ways to calculate the mode of an array of numbers. I guess I'll stick my neck out and suggest this algorithm. I don't know if this is best, but I think this works: NUB <- ( ( X iota X ) = iota rho X ) /x <- ,x FREQ <- +/ NUB jot.= X Z <- 1 take ( FREQ = max/ FREQ ) / NUB Of course in the last line it would be better to replace the "1 take" by "MIDDLE", where MIDDLE is the function that selects the middle element of a sorted vector, but I think that is another topic... Sorry, but I lost the name and address of the original poster, so can not send mail. I would be interested in seeing other solutions. -- L. J. Dickey, Faculty of Mathematics, University of Waterloo. ljdickey@water.waterloo.edu ljdickey@watdcs.BITNET ljdickey@water.UUCP ...!uunet!water!ljdickey