## input vectors
lst = list(factor(state.abb), euro, islands)
## generate 10 random products
expandGridSample(lst, n = 10, seed = 123)
## using sampleVec to generate specific results
expandGridSample(lst, sampleVec = c(1, 100, 1e3))
all.equal(expandGridSample(lst, sampleVec = 1:expandGridCount(lst)),
expandGrid(lst))
## Examples with enormous number of total results
big_lst = Map(function(x, y) x:y, 8:33, 15:40)
num = expandGridCount(big_lst)
gmp::log2.bigz(num)
## [1] 78
first = gmp::urand.bigz(n = 1, size = 78, seed = 123)
mySamp = do.call(c, lapply(0:10, function(x) gmp::add.bigz(first, x)))
class(mySamp)
## [1] "bigz"
## using the sampling function
cartSamp = expandGridSample(big_lst, sampleVec = mySamp)
## using the standard function
cartGeneral = expandGrid(big_lst,
lower = first,
upper = gmp::add.bigz(first, 10))
identical(cartSamp, cartGeneral)
## [1] TRUE
Run the code above in your browser using DataLab