I’m not sure if permutations is the correct word for this. I want to given a set of n vectors (i.e. [1,2],[3,4] and [2,3]) permute them all and get an output of
[1,3,2],[1,3,3],[1,4,2],[1,4,3],[2,3,2] etc.
Is there an operation in R that will do this?
This is a useful case for storing the vectors in a list and using
do.call()to arrange for an appropriate function call for you.expand.grid()is the standard function you want. But so you don’t have to type out or name individual vectors, try:However, for all my cleverness, it turns out that
expand.grid()accepts a list: