WOLFRAM

Commonest[list]

gives a list of the elements that are the most common in list.

Commonest[list,n]

gives a list of the n most common elements in list.

Details

  • When several elements occur with equal frequency, Commonest[list,] picks first the ones that occur first in list.
  • Commonest[list,n] returns the n commonest elements in the order they appear in list.
  • Commonest[list,UpTo[n]] returns the n commonest elements, or as many as are available.

Examples

open allclose all

Basic Examples  (3)Summary of the most common use cases

Obtain the elements with the highest frequency:

Out[1]=1

Obtain the 4 most common elements:

Out[1]=1

Obtain the 6 most common elements, or as many as there are if fewer:

Out[1]=1

Scope  (4)Survey of the scope of standard use cases

Exact input yields exact output:

Out[1]=1
Out[2]=2

Approximate input yields approximate output:

Out[1]=1
Out[2]=2

Works with large arrays:

Out[1]=1
Out[2]=2

Works with data involving quantities:

Out[1]=1
Out[2]=2

Applications  (2)Sample problems that can be solved with this function

Find the mode of a set of random integers:

Out[1]=1

Find the most frequently occurring elements in the columns of a matrix:

Out[2]=2

Find the mode for the heights of the children in a class:

Out[2]=2
Out[3]=3
Out[4]=4
Out[5]=5

Properties & Relations  (1)Properties of the function, and connections to other functions

Commonest gives elements with the largest Tally values:

Out[2]=2
Out[3]=3
Out[4]=4

Possible Issues  (1)Common pitfalls and unexpected behavior

A message is generated if there are fewer distinct elements than requested:

Out[1]=1
Wolfram Research (2007), Commonest, Wolfram Language function, https://reference.wolfram.com/language/ref/Commonest.html (updated 2015).
Wolfram Research (2007), Commonest, Wolfram Language function, https://reference.wolfram.com/language/ref/Commonest.html (updated 2015).

Text

Wolfram Research (2007), Commonest, Wolfram Language function, https://reference.wolfram.com/language/ref/Commonest.html (updated 2015).

Wolfram Research (2007), Commonest, Wolfram Language function, https://reference.wolfram.com/language/ref/Commonest.html (updated 2015).

CMS

Wolfram Language. 2007. "Commonest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Commonest.html.

Wolfram Language. 2007. "Commonest." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2015. https://reference.wolfram.com/language/ref/Commonest.html.

APA

Wolfram Language. (2007). Commonest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Commonest.html

Wolfram Language. (2007). Commonest. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/Commonest.html

BibTeX

@misc{reference.wolfram_2025_commonest, author="Wolfram Research", title="{Commonest}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/Commonest.html}", note=[Accessed: 16-April-2025 ]}

@misc{reference.wolfram_2025_commonest, author="Wolfram Research", title="{Commonest}", year="2015", howpublished="\url{https://reference.wolfram.com/language/ref/Commonest.html}", note=[Accessed: 16-April-2025 ]}

BibLaTeX

@online{reference.wolfram_2025_commonest, organization={Wolfram Research}, title={Commonest}, year={2015}, url={https://reference.wolfram.com/language/ref/Commonest.html}, note=[Accessed: 16-April-2025 ]}

@online{reference.wolfram_2025_commonest, organization={Wolfram Research}, title={Commonest}, year={2015}, url={https://reference.wolfram.com/language/ref/Commonest.html}, note=[Accessed: 16-April-2025 ]}