Here is one possible solution: for(cr in seq(1, dim(combin_mat)[2])) { W = which(input_mat[,combin_mat[1,cr]] == 1 & input_mat[,combin_mat[2,cr]] == 1) cat("Combination", cr, "(", combin_mat[,cr], ") :", W, "\n") }
JeeBee. --- Full program: N = 4 input_numbers = seq((2^N)-1, 0, -1) # convert to binary matrix input_mat = NULL for(i in seq(N-1,0,-1)) { new_col = input_numbers %% 2 input_mat = cbind(new_col, input_mat) input_numbers = (input_numbers - new_col) / 2 } colnames(input_mat) = NULL library(gtools) combin_mat = t(combinations(n=N, r=2, v=1:N, set=TRUE, repeats.allowed=FALSE)) for(cr in seq(1, dim(combin_mat)[2])) { W = which(input_mat[,combin_mat[1,cr]] == 1 & input_mat[,combin_mat[2,cr]] == 1) cat("Combination", cr, "(", combin_mat[,cr], ") :", W, "\n") } ______________________________________________ R-help@stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html