I want to map a number of relationship circles (consisting of a list of id
s) into a large adjacency matrix. My data looks like this
circle_1 = c(1, 3, 5)
circle_2 = c(17, 22, 35, 49)
circle_3 = c(2, 9)
circle_4 = c(12, 28, 33)
circle_5 = c(1, 3, 8, 16, 40)
d_mat = matrix(ncol = 2)
for (i in 1:5) {
#extract id from list
dat = get(paste("circle", i, sep="_"))
#convert to edgelist, each pair is unique
dat_t = t(combn(dat, 2))
#rbind edge list together
edge_list <- rbind(d_mat, dat_t)
}
However, the output edge_list
only returns the edge list of from the last iteration (circle_5
) with the preceding three being overwritten.
Furthermore, suppose these five circles were drawn from a group of 50 persons, how can I map the values of such edge list to the corresponding cells of a 50 by 50 adjacency matrix? (I suppose make_graph
and as_adjacency_matrix
function in igraph
should do the tricks, but I don't know how at the moment)
Also, for overlapping membership, such (1, 3) in circle_1
and circle_5
, meaning that 1 and 3 are linked twice in this 50-person network. How can I aggregate this count frequency and convert the adjacency matrix into a weighted matrix?