[R] Finding all possible partitions of N units into k classes

Ales Ziberna aleszib at gmail.com
Thu Dec 8 15:45:37 CET 2005


Dear useRs!



I would like to generate a list of all possible (unique) partitions of N 
units into k classes. For example, all possible partitions of 4 units into 2 
classes are (I hope I have not missed anyone):

1,1,1,2 (this can be read as {1,2,3},{4})

1,1,2,1

1,2,1,1

2,1,1,1

1,1,2,2

1,2,1,2

1,2,2,1



The partitions 1,1,2,2 and 2,2,1,1 are the same and are therefore not two 
unique partitions.



Thank you in advance for any suggestions.

Best,

Ales Ziberna




More information about the R-help mailing list