You can use outer if m is your square matrix:
f = Vectorize(function(u,v) any(colSums(m[c(u,v),])>1)+0L) res = outer(1:ncol(m), 1:ncol(m), FUN=f) colnames(res) = row.names(res) = rownames(m) # ABCDE #A 1 1 1 0 0 #B 1 1 0 1 1 #C 1 0 1 0 0 #D 0 1 0 1 0 #E 0 1 0 0 1
Data:
m = structure(c(0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 1), .Dim = c(5L, 5L), .Dimnames = list(c("A", "B", "C", "D", "E"), NULL))
Colonel beauvel
source share