实现这一目标的方法多种多样。它看起来像是用图论的术语
   
    igraph
   
  
  circles <- list(1:3, 2:4) # Friendship circles with identities 1, ..., n
n <- max(unlist(circles)) # Total number of people
nM <- matrix(0, n, n) # n x n matrix of zeroes
  
   那么
  
  adjs <- lapply(circles, function(cr) {nM[cr, cr] <- 1; nM[cbind(cr, cr)] <- 0; nM})
  
   是每个友谊圈的n x n邻接矩阵的列表(每种情况下大多为零)。
  
  
  
  (adj1 <- Reduce(`+`, adjs))
#      [,1] [,2] [,3] [,4]
# [1,]    0    1    1    0
# [2,]    1    0    2    1
# [3,]    1    2    0    1
# [4,]    0    1    1    0
(adj2 <- 1 * (adj1 > 0))
#      [,1] [,2] [,3] [,4]
# [1,]    0    1    1    0
# [2,]    1    0    1    1
# [3,]    1    1    0    1
# [4,]    0    1    1    0