Description Usage Arguments Format Details See Also Examples
This function returns a Combinations iterator for iterating
combinations of k
items from n
items. The iterator allows users to fetch the next
combination(s) via the getnext()
method.
1 2 3 4 | Combinations
icombinations(x = NULL, k = NULL, n = NULL, v = NULL,
freq = NULL, replace = FALSE, skip = NULL)
|
x |
an integer or a vector, will be treated as |
k |
an integer, the number of items drawn, defaults to |
n |
an integer, the total number of items, its value may be implicitly deduced from |
v |
a vector to be drawn, defaults to |
freq |
an integer vector of item repeat frequencies |
replace |
an logical to draw items with replacement |
skip |
the number of combinations skipped |
An object of class R6ClassGenerator
of length 25.
The Combinations
class can be initialized by using the convenient wrapper icombinations
or
1 |
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
combinations for generating all combinations and ncombinations to calculate number of combinations
1 2 3 4 5 6 7 8 9 10 11 | icomb <- icombinations(5, 2)
icomb$getnext()
icomb$getnext(2)
icomb$getnext(layout = "column", drop = FALSE)
# collect remaining combinations
icomb$collect()
library(foreach)
foreach(x = icombinations(5, 2), .combine=c) %do% {
sum(x)
}
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.