Everyone, I have this binary matrix
rownames <- c("gene1", "gene2", "gene3", "gene4")
colnames <- c("A", "B", "C", "D")
data <- matrix(c(1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1),nrow = 4, ncol = 4, byrow = TRUE, dimnames = list(rownames, colnames))
data
# A B C D
#gene1 1 0 1 0
#gene2 1 1 0 0
#gene3 1 0 1 0
#gene4 0 1 0 1
I would like to turn data into this Adjacency matrix for network igraph
visualization.
A B C D
A 0 1 2 0
B 1 0 0 1
C 2 0 0 0
D 0 1 0 0
Explanation: from A, gene2 has shared score "1" with B, that is why I gets 1 score. from A, gene1 and gene3 has shared score "total 2" with C, that is why it gets 2 score
Is it possible to change matrix into this? Should I use iteration? but I have no idea. Tidyverse approach will be very helpful.
Thank you