[R] function for grouping

Petr Savicky savicky at cs.cas.cz
Thu Jan 26 18:13:32 CET 2012

On Thu, Jan 26, 2012 at 08:29:22AM -0800, yan wrote:
> what if I don't need to store the combination results, I just want to get the
> combination result for a given row.
> e.g. for the 5 elements divided into 3 groups , and if I give another
> parameter which is the row number of the results, in petr's example, say if
> I set row number to 1, then I get 1,2,3,1,1.
> So I need a systematic way of generating the combination, but I don't need
> all the combinations in one go.
> Many thanks!!!!


I suppose that your question is meant for some larger
example than 5 elements into 3 groups, since for this
small case, we can store the whole table.

Considering, for example, 200 elements and 3 groups, which
you mentioned previously, this can probably be done using
some implementation of large integers. The reason is that
the final table has approximately 3^200/6 rows. So, the index
of the last row has approx log2(3^200/6) = 314.4 bits.
The standard numbers have 53 bits. For large integers,
one can use packages "gmp", "Rmpfr" or some package
for symbolic algebra, for example "Ryacas".

Do you want to use a large integer m for a search of
the exactly m-th partitioning in lexicographic order?

Let me point out that sampling random partitionings can
be done much easier.


More information about the R-help mailing list