Description Usage Arguments Format Details See Also Examples
This function returns a Compositions iterator for iterating
compositions of an non-negative integer n
into k
parts or parts of any sizes.
The iterator allows users to fetch the next partition(s) via the getnext()
method.
1 2 3 | Compositions
icompositions(n, k = NULL, descending = FALSE, skip = NULL)
|
n |
an non-negative integer to be partitioned |
k |
number of parts |
descending |
an logical to use reversed lexicographical order |
skip |
the number of compositions skipped |
An object of class R6ClassGenerator
of length 25.
The Compositions
class can be initialized by using the convenient wrapper icompositions
or
1 | Compositions$new(n, k = NULL, descending = FALSE)
|
1 2 3 |
number of fetched arrangements
if "row", "column" or "list" is specified, the returned value would be a "row-major" matrix, a "column-major" matrix or a list respectively
vectorize a matrix or unlist a list
compositions for generating all compositions and ncompositions to calculate number of compositions
1 2 3 4 5 6 7 8 9 10 11 | ipart <- icompositions(4)
ipart$getnext()
ipart$getnext(2)
ipart$getnext(layout = "column", drop = FALSE)
# collect remaining compositions
ipart$collect()
library(foreach)
foreach(x = icompositions(6, 2), .combine=c) %do% {
prod(x)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.