icomb: Combination Iterator

Description Usage Arguments Details Value Examples

View source: R/icomb.R

Description

Create an iterator for all combinations k integers out of 1 through n.

Usage

1
2
3
icomb(n, k)

icombv(values, k)

Arguments

n

positive integer

k

positive integer no greater than n

values

iterable (subsettable by [)

Details

Value

iterator object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
x <- icomb(5, 3)
ct <- 0
while (hasNext(x))
{
  ct <- ct + 1
  i <- nextElem(x)
  cat(sprintf("%3d : %s\n", ct, paste0(i, collapse = " ")))
}

as.list(icombv(c("A", "G", "C"), 2))

Example output

  1 : 1 2 3
  2 : 1 2 4
  3 : 1 2 5
  4 : 1 3 4
  5 : 1 3 5
  6 : 1 4 5
  7 : 2 3 4
  8 : 2 3 5
  9 : 2 4 5
 10 : 3 4 5
[[1]]
[1] "A" "G"

[[2]]
[1] "A" "C"

[[3]]
[1] "G" "C"

combiter documentation built on May 2, 2019, 7:24 a.m.