I am using expand.grid
to generate all of the pairs of the elements of a vector, such as:
v <- 1:3
expand.grid(v,v)
Which gives:
Var1 Var2
1 1 1
2 2 1
3 3 1
4 1 2
5 2 2
6 3 2
7 1 3
8 2 3
9 3 3
Now, say I want the same thing but with triplets I use
expand.grid(v,v,v)
How would I go about generalizing this to n-tuples so that I can use new.expand.grid(v,5)
and have the result of expand.grid(v,v,v,v,v)
?