Description Usage Arguments Details Value Examples
Constructs an iterator that is the Cartesian product of each of the arguments.
1 |
... |
multiple arguments |
Although they share the same end goal, iproduct
can yield drastic
memory savings compared to expand.grid
.
iterator that iterates through each element from the Cartesian product
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | it <- iproduct(x=1:3, y=4:5)
iterators::nextElem(it) # list(x=1, y=4)
iterators::nextElem(it) # list(x=1, y=5)
iterators::nextElem(it) # list(x=2, y=4)
iterators::nextElem(it) # list(x=2, y=5)
iterators::nextElem(it) # list(x=3, y=4)
iterators::nextElem(it) # list(x=3, y=5)
# iproduct is a replacement for base::expand.grid()
# Large data.frames are not created unless the iterator is manually consumed
a <- 1:2
b <- 3:4
c <- 5:6
it2 <- iproduct(a=a, b=b, c=c)
df_iproduct <- do.call(rbind, as.list(it2))
df_iproduct <- data.frame(df_iproduct)
# Compare df_iproduct with the results from base::expand.grid()
base::expand.grid(a=a, b=b, c=c)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.