I'm wondering if there's a way to quickly calculate the number of shared neighbors between any pairs of nodes (i.e., the number of nodes connected to both node i and j) from an adjacency matrix (like the one below) and then return the output in matrix format?
I've referenced these following posts, Find common neighbors of selected vertices Counting the number of neighbors in common between two vertices in R Calculate number of common neighbors in igraph R
but can't seem to find many clues to do what I want to achieve. I was told that this can be directly calculated as adjm'
*adjm
, but I am not sure if this makes sense. It will be really appreciated if someone could shed some light on this.
# create an adj. matrix
adjm <- matrix(sample(0:1, 100, replace=TRUE, prob=c(0.6,0.4)), nc=10)
# set diagonal element to 0
diag(adjm) <- 0
# making it symmetric
adjm[lower.tri(adjm)] = t(adjm)[lower.tri(adjm)]