[英](R Igraph) Using affilliation to create subgraph from adjacency matrix
I need to create a subgraph from an adjacency matrix selecting by affiliation data. 我需要从通过关联数据选择的邻接矩阵创建一个子图。 How do I match an adjacency and an affiliation matrix?
如何匹配邻接关系和隶属关系矩阵?
Take the following adjacency matrix: 采取以下邻接矩阵:
A B C D E F G
A 0 1 0 1 0 1 0
B 1 0 1 1 0 1 0
C 0 1 0 0 0 0 0
D 1 1 0 0 1 1 0
E 0 0 0 1 0 1 0
F 1 1 0 1 1 0 1
G 0 0 0 0 0 1 0
And the following affiliation matrix: 以及以下隶属关系矩阵:
P R Q
A 1 1 0
B 1 0 1
C 1 1 0
D 0 1 0
E 1 0 1
F 0 0 1
G 1 1 0
How do I create a subgraph from the adjacency matrix only with the nodes corresponding to P in the affiliation matrix? 如何仅使用隶属关系矩阵中与P对应的节点从邻接关系矩阵创建子图?
If your goal is to: 如果您的目标是:
P
is 1
in the affiliation matrix P
为1
节点 igraph
object igraph
对象 then you can accomplish that with the following: 那么您可以通过以下操作完成此操作:
# the names(which()) isn't needed for the subset of adj
p_nodes <- names(which(aff[,"P"] == 1))
p_adj <- adj[p_nodes, p_nodes]
p_graph <- igraph::graph.adjacency(p_graph)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.