create all unique combinations between elements of a vector R
#Create unique pairwise permutations between elements of a vector
install.packages("RcppAlgos") #only run it once
x <- c("Red", "Blue", "Green", "Yellow")
library(RcppAlgos)
comboGeneral( names(table(x)) , m=2, freqs = table(x))
#Output:
[,1] [,2]
[1,] "Blue" "Green"
[2,] "Blue" "Red"
[3,] "Blue" "Yellow"
[4,] "Green" "Red"
[5,] "Green" "Yellow"
[6,] "Red" "Yellow"
#You can store it in a data frame for easy access
combinations <- as.data.frame( comboGeneral( names(table(x)) , m=2, freqs = table(x)) )