I have data set and want to subset it to several data sets using all possible combinations of specific factor, giving that each combination should contain 4 levels and appear once.
here is some codes to generate very simple example:
data<-cbind(rep(1:8,each=2),matrix(nrow=16, ncol=4,rnorm(160, mean = 0, sd = 1)))
colnames(data)<-LETTERS[1:5]
> data
"A" B C D E
[1,] 1 -0.07929477 -1.2946058 -1.4072064 0.57159386
[2,] 1 1.83963909 -1.1723990 1.1232986 0.39483666
[3,] 2 -0.36423210 1.3240148 1.3274450 -0.96929628
[14,] 7 1.46756745 -0.7885119 -0.4218986 -1.25255228
[15,] 8 -0.42291051 0.2915121 0.4320183 1.37582031
[16,] 8 -0.40031215 0.4627476 -0.4145012 0.28700559
"A" is factor with 8 levels, i want to choose all possible 4 combinations ( i.e 1 2 3 4, 1 2 3 5 etc) out of the 8 levels and use that combinations to split "data" to several data sets to be used in further analysis.