icartes: Cartesian Product Iterator

View source: R/icartes.R

icartesR Documentation

Cartesian Product Iterator

Description

Create an iterator going through Cartesian product of several items.

Usage

icartes(nvec)

icartesv(...)

Arguments

nvec

integer vector of number of items

...

set of iterables (subsettable by [)

Details

  • icartes iterates through all combinations of integers

  • icartesv iterates through all combinations of general values

Value

iterator object

Examples

x <- icartes(c(3, 2, 4))
ct <- 0
while (hasNext(x))
{
  ct <- ct + 1
  i <- nextElem(x)
  cat(sprintf("%3d : %s\n", ct, paste0(i, collapse = " ")))
}

x <- icartesv(Month=c("Jan", "Feb", "Mar"),
              Loc=c("NY", "LA"),
              By=c("car", "plane", "bus"))
as.list(x)

kota7/combiter documentation built on June 14, 2025, 11:08 a.m.