Maybe this is what you are after
> `diag<-`(crossprod(as.matrix(df)),NA)
A B C D
A NA 2 1 3
B 2 NA 2 2
C 1 2 NA 2
D 3 2 2 NA
Data
> dput(df)
structure(list(A = c(1L, 0L, 1L, 0L, 1L, 1L), B = c(0L, 1L, 1L,
0L, 1L, 0L), C = c(0L, 1L, 0L, 1L, 1L, 0L), D = c(0L, 0L, 1L,
1L, 1L, 1L)), class = "data.frame", row.names = c("a", "b", "c",
"d", "e", "f"))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…