Skip to content

Commonest ​

Every element tied for the most frequently occurring in the collection.

✓ checked against that system · ! checked, with disagreements (hover a chip)Wolfram LanguageCommonest✓
Commonest(collection)every element tied for the highest frequency, in the order first encountered.
Commonest(collection, n)the nn commonest elements, ties broken by first appearance, listed in order of first appearance.
Typed signatures
TypePackageApplies
(indexed_collection<T>, integer?) -> list<T> where Tcombinatoricsalways

Domain: Collections

Details
  • Wolfram's answer to a tied Mode: where Mode picks one, Commonest returns every value tied for the highest frequency.
  • With a unique mode, Commonest(c)={Mode(c)}Commonest(c) = \{Mode(c)\}: a single-element list.
  • Every returned value occurs exactly as many times as the highest frequency in the collection. See Count.

Examples

Basic #
live ↗
InCommonest([1,1,2,2,3])\mathrm{Commonest}(\bigl\lbrack1, 1, 2, 2, 3\bigr\rbrack)Out[1,2]\bigl\lbrack1, 2\bigr\rbrack

With a unique mode, Commonest returns a single-element list

live ↗
InCommonest([1,2,2,3])\mathrm{Commonest}(\bigl\lbrack1, 2, 2, 3\bigr\rbrack)Out[2]\bigl\lbrack2\bigr\rbrack

Every element tied for most frequent, symbols and numbers alike

live ↗
InCommonest([b,a,c,2,a,b,1,2])\mathrm{Commonest}(\bigl\lbrack b, a, c, 2, a, b, 1, 2\bigr\rbrack)Out[b,a,2]\bigl\lbrack b, a, 2\bigr\rbrack

A single most-frequent element still comes back in a list

live ↗
InCommonest([1,2,2,3,3,3,4])\mathrm{Commonest}(\bigl\lbrack1, 2, 2, 3, 3, 3, 4\bigr\rbrack)Out[3]\bigl\lbrack3\bigr\rbrack
live ↗
InCommonest([b,a,c,2,a,b,1,2],4)\mathrm{Commonest}(\bigl\lbrack b, a, c, 2, a, b, 1, 2\bigr\rbrack, 4)Out[b,a,c,2]\bigl\lbrack b, a, c, 2\bigr\rbrack
live ↗
InCommonest([b,a,c,2,a,b,1,2],UpTo(6))\mathrm{Commonest}(\bigl\lbrack b, a, c, 2, a, b, 1, 2\bigr\rbrack, \mathrm{UpTo}(6))Out[b,a,c,2,1]\bigl\lbrack b, a, c, 2, 1\bigr\rbrack
Scope #

All distinct: all tie

live ↗
InCommonest([1,2,3])\mathrm{Commonest}(\bigl\lbrack1, 2, 3\bigr\rbrack)Out[1,2,3]\bigl\lbrack1, 2, 3\bigr\rbrack

The nn commonest, ties broken by first appearance

live ↗
InCommonest([1,2,2,3,3,3,4],2)\mathrm{Commonest}(\bigl\lbrack1, 2, 2, 3, 3, 3, 4\bigr\rbrack, 2)Out[2,3]\bigl\lbrack2, 3\bigr\rbrack

Numeric input still picks the most frequent value, 3

live ↗
InCommonest(N([1,2,2,3,3,3,4]))\mathrm{Commonest}(N(\bigl\lbrack1, 2, 2, 3, 3, 3, 4\bigr\rbrack))Out[3.0]\bigl\lbrack3.0\bigr\rbrack

Higher-precision numeric input gives the same mode

live ↗
InCommonest(N([1,2,2,3,3,3,4],30))\mathrm{Commonest}(N(\bigl\lbrack1, 2, 2, 3, 3, 3, 4\bigr\rbrack, 30))Out[3.0]\bigl\lbrack3.0\bigr\rbrack
live ↗
InCommonest(data)\mathrm{Commonest}(\mathrm{data})OutCommonest(data)\mathrm{Commonest}(\mathrm{data})
live ↗
InCommonest([a,e,sin⁡(y),e,a,7])\mathrm{Commonest}(\bigl\lbrack a, e, \sin(y), e, a, 7\bigr\rbrack)Out[a,e]\bigl\lbrack a, e\bigr\rbrack
Applications #
live ↗
InCommonest(heights)\mathrm{Commonest}(\mathrm{heights})OutCommonest(heights)\mathrm{Commonest}(\mathrm{heights})
Properties #

With a unique mode, Commonest(c)={Mode(c)}Commonest(c) = \{Mode(c)\}. See Mode

live ↗
InFirst(Commonest([1,2,2,3]))\mathrm{First}(\mathrm{Commonest}(\bigl\lbrack1, 2, 2, 3\bigr\rbrack))Out22

Without a tie, the single commonest element is the Mode

live ↗
InFirst(Commonest([1,2,2,3,3,3,4]))=Mode([1,2,2,3,3,3,4])\mathrm{First}(\mathrm{Commonest}(\bigl\lbrack1, 2, 2, 3, 3, 3, 4\bigr\rbrack))=\mathrm{Mode}(\bigl\lbrack1, 2, 2, 3, 3, 3, 4\bigr\rbrack)OutTrue\mathrm{True}

A frequency tie between 44 and 11 is broken by first appearance in the list.

live ↗
InCommonest([4,1,1,4],1)\mathrm{Commonest}(\bigl\lbrack4, 1, 1, 4\bigr\rbrack, 1)Out[4]\bigl\lbrack4\bigr\rbrack
About
Examples16
Checked againstWolfram Language 16 agree
CrosswalkWolfram Language

See also: Mode, Mean, Median