Macaulay2 » Documentation
Packages » Macaulay2Doc :: commonest
next | previous | forward | backward | up | index | toc

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 :

For the programmer

The object commonest is a method function with a single argument.