I need to make a matrix/data frame containing all combinations of the elements in two vectors. All combinations must be unique, and include different elements. I know I can use the following to make a list of all combinations:
a<-c("cat","dog","cow")
b<-c("dog","cow","sheep")
combination<-as.matrix(expand.grid(a,b))
And that I can remove entries where both elements are the same using this:
combination1<-combination[combination[,1]!=combination[,2],]
Which gives the following output:
> combination1
Var1 Var2
[1,] "cat" "dog"
[2,] "cow" "dog"
[3,] "cat" "cow"
[4,] "dog" "cow"
[5,] "cat" "sheep"
[6,] "dog" "sheep"
[7,] "cow" "sheep"
What I need is to detect/remove rows with the same strings, but in a different order (rows 2 and 4 are "cow,dog", and "dog,cow". Is there a simple way to do this in R? I'm writing a script to test interactions between genes in barley which is very lengthy, and I want to avoid testing the same combination twice. Any help would be appreciated.