Learn R Programming

combiter (version 1.0.3)

icomb: Combination Iterator

Description

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

Usage

icomb(n, k)

icombv(values, k)

Arguments

n

positive integer

k

positive integer no greater than n

values

iterable (subsettable by [)

Value

iterator object

Details

  • icomb iterates through integer vectors

  • icombv iterates through general values

Examples

Run this code
# NOT RUN {
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))
# }

Run the code above in your browser using DataLab