I want to call a function for all combinations of arguments. For this, 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, epsilonin addition to typeand cost).
source
share