expand.grids <- function(x,d) {
expand.grid(replicate(d, x, simplify=FALSE))
}
expand.grids(1:2,4)
Var1 Var2 Var3 Var4
1 1 1 1 1
2 2 1 1 1
3 1 2 1 1
4 2 2 1 1
5 1 1 2 1
6 2 1 2 1
7 1 2 2 1
8 2 2 2 1
9 1 1 1 2
10 2 1 1 2
11 1 2 1 2
12 2 2 1 2
13 1 1 2 2
14 2 1 2 2
15 1 2 2 2
16 2 2 2 2