I want to call a function on all combinations of arguments.
For that end I tried outer
:
> outer(c(0,6,7),c(100,10,1,0.1,0.01),FUN=list)
Error in outer(c(0, 6, 7), c(100, 10, 1, 0.1, 0.01), FUN = list) :
dims [product 15] do not match the length of object [2]
I can get what I want using nested lapply
:
do.call(c,lapply(c(0,6,7),function(type)
lapply(c(100,10,1,0.1,0.01),function(cost)
list(type=type,cost=cost)))
but I wonder if there is a better solution (especially if I have more than two variables, say, epsilon
in addition to type
and cost
).