library(e1071) library(prodlim) MAT=matrix(0,5,5) for(r in 2:5) { for(s in 2:5) { K=r*s Indr<-combn(1:r, 2) Inds<-combn(1:s, 2) Gridrs<-expand.grid(Indr[,1],Inds) if(ncol(Indr)>1) for(i in 2:ncol(Indr)) Gridrs<-rbind(Gridrs,expand.grid(Indr[,i],Inds)) ALLInd<-expand.grid(1:r,1:s) M=bincombinations(K) indset<-matrix(0,nrow(Gridrs)/4,4) for(i in 1:(nrow(Gridrs)/4)) indset[i,]<-row.match(Gridrs[(4*(i-1)+1):(4*(i-1)+4),],ALLInd) count=0 mine1=c(0,1,1,0) mine2=c(1,0,0,1) infset=vector() for(i in 1:(2^K)) { table<-t(sapply(1:nrow(indset),function(j)M[i,indset[j,]])) row.is.a.match1<- apply(table, 1, identical, mine1) row.is.a.match2 <- apply(table, 1, identical, mine2) if(any(row.is.a.match1==TRUE)|any(row.is.a.match2==TRUE)) {infset=c(infset,i) count=count+1 } } MAT[r,s]=count gc(verbose=FALSE) } } print(MAT)