Last chance! 50% off unlimited learning
Sale ends in
This function returns a Combinations iterator which
allows users to fetch the next combination(s) via the getnext()
method. All remaing
combinations of the iterator can be fetched via the collect()
method.
Combinationsicombinations(n, k, x = NULL, freq = NULL, replace = FALSE)
an integer, would be determined implicitly from x
or f
if missing
an integer
an optional vector indicating item labels
an integer vector of item repeat frequencies
an logical to draw items with replacement
An object of class R6ClassGenerator
of length 24.
The Combinations
class can be initialized by using the convenient wrapper icombinations
or
Combinations$new(n, k, x = NULL, freq = NULL, replace = FALSE)
getnext(d = 1L, type = NULL, drop = d == 1L && is.null(type)) collect(type = "r") reset()
number of fetched arrangements
if "r", "c" or "l" 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
# NOT RUN {
icomb <- icombinations(5, 2)
icomb$getnext()
icomb$getnext(2)
icomb$getnext(type = "c", drop = FALSE)
# collect remaining combinations
icomb$collect()
library(foreach)
foreach(x = icombinations(5, 2), .combine=c) %do% {
sum(x)
}
# }
Run the code above in your browser using DataLab