gpt4 book ai didi

r - 如何使用 R 将大型 igraph 子集到一个节点及其连接的节点?

转载 作者:行者123 更新时间:2023-12-02 04:30:02 27 4
gpt4 key购买 nike

我在 R 中有一个非常大的 igraph(称为 g)。

我只对一个节点 (NodeA) 以及直接连接到 NodeA 的任何节点感兴趣。我想最终得到一个非常简单的图表,如下图所示。

我试过 subgraph(g, "nodeA") 但我最终只得到了 NodeA。

我想我需要将图 g 的边子集到连接到 nodeA 的边,然后使用 subgraph.edges()。我无法弄清楚如何根据边缘连接到的节点对边缘进行子集化...

NodeA and two directly connected nodes

最佳答案

尝试使用 neighbors()

# Example graph
g1 <- graph_from_literal(1:2:3---3:4:5)

# Let's take a look at it
plot(g1)

enter image description here
# 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)

enter image description here

关于r - 如何使用 R 将大型 igraph 子集到一个节点及其连接的节点?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49809744/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com