我在R中有一个很大的字样(称为g)。
我只对一个节点(NodeA)以及直接连接到NodeA的所有节点感兴趣。我想得到一个非常简单的图形,如下图所示。
我已经尝试过subgraph(g,“nodeA”),但是我最终只能单独使用NodeA。
我想我需要将图g的边缘子集化为那些连接到nodeA的边缘,然后使用subgraph.edges()。我不知道如何根据它们连接到的节点来对边缘进行子集化...
最佳答案
尝试使用neighbors()
# Example graph
g1 <- graph_from_literal(1:2:3---3:4:5)
# Let's take a look at it
plot(g1)
# Say we are interested in the subgraph consisting of vertex 1 and all
# other vertices it is connected to
g2 <- induced_subgraph(g1, c(1, neighbors(g1,1)))
plot(g2)
关于r - 如何使用R将大型igraph子集化为仅一个节点及其连接的节点?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49809744/