comboGrid {RcppAlgos} | R Documentation |
Efficient Version of expand.grid
Where order Does Not Matter
Description
This function efficiently generates Cartesian-product-like output where order does not matter. It is loosely equivalent to the following:
t = expand.grid(list)
t = t[do.call(order, t), ]
key = apply(t, 1, function(x) paste0(sort(x), collapse = ""))
t[!duplicated(key), ]
Usage
comboGrid(..., repetition = TRUE)
Arguments
... |
vectors, factors or a list containing these. (See |
repetition |
Logical value indicating whether results should be with or without repetition. The default is |
Value
If items with different classes are passed, a data frame will be returned, otherwise a matrix will be returned.
Author(s)
Joseph Wood
Examples
## return a matrix
expGridNoOrder = comboGrid(1:5, 3:9, letters[1:5], letters[c(1,4,5,8)])
head(expGridNoOrder)
tail(expGridNoOrder)
expGridNoOrderNoRep = comboGrid(1:5, 3:9, letters[1:5],
letters[c(1,4,5,8)], repetition = FALSE)
head(expGridNoOrderNoRep)
tail(expGridNoOrderNoRep)
[Package RcppAlgos version 2.8.3 Index]