partitions: Generate partitions of n items constrained into k non empty...

View source: R/partitions.R

partitionsR Documentation

Generate partitions of n items constrained into k non empty subsets


Generate all possible partitions of n items constrained into k non empty subsets. It does not generate the universe of rankings constrained into k buckets.


partitions(n, k = NULL, items = NULL, itemtype = "L")



a (integer) number denoting the number of items


The number of the non-empty subsets. Default value is NULL, in this case all the possible partitions are displayed


items: the items to be placed into the ordering matrix. Default are the first c small letters


to be used only if items is not set. The default value is "L", namely letters. Any other symbol produces items as the first c integers


If the objects to be ranked is large (>15-20) with some missing, it can take long time to find the solutions. If the searching space is limited to the space of full rankings (also incomplete rankings, but without ties), use the function BBFULL or the functions FASTcons and QuickCons with the option FULL=TRUE.


the ordering matrix (or vector)


Antonio D'Ambrosio

See Also

stirling2 Stirling number of second kind.

rank2order Convert rankings into orderings.

order2rank Convert orderings into ranks.

univranks Generate the universe of rankings given the input partition


#shows all the ways to partition 4 items (say "a", "b", "c" and "d" into 3 non-empty subets
 #(i.e., into 3 buckets). The Stirling number of the second kind (4,3) indicates that there
 #are 6 ways.
X2<-order2rank(X) #it transform the ordering into ranking

ConsRank documentation built on March 31, 2023, 7:25 p.m.