next | previous | forward | backward | up | top | index | toc | Macaulay2 web site
Macaulay2Doc :: commonest

commonest -- the most common elements of a list or tally

Synopsis

Description

If a single element is the most common, a list of length one is the output.

i1 : commonest {a,a,a,a,b,b,b,c,c,d,e}

o1 = {a}

o1 : List

In the case of a tie, all commonest elements are returned.

i2 : A = {a,a,a,a,b,b,b,b,c,c,c,c,d,e}; commonest A

o3 = {c, a, b}

o3 : List

commonest works on Tallys and Sets as well.

i4 : T = tally A

o4 = Tally{a => 4}
           b => 4
           c => 4
           d => 1
           e => 1

o4 : Tally
i5 : commonest T

o5 = {c, a, b}

o5 : List
i6 : S = set A

o6 = set {a, b, c, d, e}

o6 : Set
i7 : commonest S

o7 = {c, d, e, a, b}

o7 : List

(Since every element of a set is unique, it is unclear why one would need commonest(Set).)

See also

Ways to use commonest :