I can see from the link below how to get a list of unique combinations and then how to combine this with self combinations
Non-redundant version of expand.grid
e.g.
factors <- c("a", "b", "c")
all.combos <- t(combn(factors,2))
dup.combos <- cbind(factors,factors)
all.combosnew <- rbind(all.combos,dup.combos)
factors factors
[1,] "a" "b"
[2,] "a" "c"
[3,] "b" "c"
[4,] "a" "a"
[5,] "b" "b"
[6,] "c" "c"
However, I also need there to be duplicates of correlations, so there should be 9 combinations altogether
"a" "a"
"a" "b"
"a" "c"
"b" "a"
"b" "b"
"b" "c"
"c" "a"
"c" "b"
"c" "c"
This seems like it should be obvious, but I haven't found it yet. Any suggestions would be helpful.
Ultimately, I need to put this list of combinations into a foreach loop using cor.test and need all combinations to be listed, such that I can convert this into a matrix e.g 3x3.
a b c
1 x x
x 1 x
x x 1