icartes: Cartesian Product Iterator

Description Usage Arguments Details Value Examples

View source: R/icartes.R

Description

Create an iterator going through Cartesian product of several items.

Usage

1
2
3

Arguments

nvec

integer vector of number of items

...

set of iterables (subsettable by [)

Details

Value

iterator object

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
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)

Example output

  1 : 1 1 1
  2 : 1 1 2
  3 : 1 1 3
  4 : 1 1 4
  5 : 1 2 1
  6 : 1 2 2
  7 : 1 2 3
  8 : 1 2 4
  9 : 2 1 1
 10 : 2 1 2
 11 : 2 1 3
 12 : 2 1 4
 13 : 2 2 1
 14 : 2 2 2
 15 : 2 2 3
 16 : 2 2 4
 17 : 3 1 1
 18 : 3 1 2
 19 : 3 1 3
 20 : 3 1 4
 21 : 3 2 1
 22 : 3 2 2
 23 : 3 2 3
 24 : 3 2 4
[[1]]
[[1]]$Month
[1] "Jan"

[[1]]$Loc
[1] "NY"

[[1]]$By
[1] "car"


[[2]]
[[2]]$Month
[1] "Jan"

[[2]]$Loc
[1] "NY"

[[2]]$By
[1] "plane"


[[3]]
[[3]]$Month
[1] "Jan"

[[3]]$Loc
[1] "NY"

[[3]]$By
[1] "bus"


[[4]]
[[4]]$Month
[1] "Jan"

[[4]]$Loc
[1] "LA"

[[4]]$By
[1] "car"


[[5]]
[[5]]$Month
[1] "Jan"

[[5]]$Loc
[1] "LA"

[[5]]$By
[1] "plane"


[[6]]
[[6]]$Month
[1] "Jan"

[[6]]$Loc
[1] "LA"

[[6]]$By
[1] "bus"


[[7]]
[[7]]$Month
[1] "Feb"

[[7]]$Loc
[1] "NY"

[[7]]$By
[1] "car"


[[8]]
[[8]]$Month
[1] "Feb"

[[8]]$Loc
[1] "NY"

[[8]]$By
[1] "plane"


[[9]]
[[9]]$Month
[1] "Feb"

[[9]]$Loc
[1] "NY"

[[9]]$By
[1] "bus"


[[10]]
[[10]]$Month
[1] "Feb"

[[10]]$Loc
[1] "LA"

[[10]]$By
[1] "car"


[[11]]
[[11]]$Month
[1] "Feb"

[[11]]$Loc
[1] "LA"

[[11]]$By
[1] "plane"


[[12]]
[[12]]$Month
[1] "Feb"

[[12]]$Loc
[1] "LA"

[[12]]$By
[1] "bus"


[[13]]
[[13]]$Month
[1] "Mar"

[[13]]$Loc
[1] "NY"

[[13]]$By
[1] "car"


[[14]]
[[14]]$Month
[1] "Mar"

[[14]]$Loc
[1] "NY"

[[14]]$By
[1] "plane"


[[15]]
[[15]]$Month
[1] "Mar"

[[15]]$Loc
[1] "NY"

[[15]]$By
[1] "bus"


[[16]]
[[16]]$Month
[1] "Mar"

[[16]]$Loc
[1] "LA"

[[16]]$By
[1] "car"


[[17]]
[[17]]$Month
[1] "Mar"

[[17]]$Loc
[1] "LA"

[[17]]$By
[1] "plane"


[[18]]
[[18]]$Month
[1] "Mar"

[[18]]$Loc
[1] "LA"

[[18]]$By
[1] "bus"

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