Learn R Programming

combiter (version 1.0.3)

icartes: 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 [)

Value

iterator object

Details

  • icartes iterates through all combinations of integers

  • icartesv iterates through all combinations of general values

Examples

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

Run the code above in your browser using DataLab