Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用R将大型igraph子集为一个节点及其连接的节点?_R_Igraph - Fatal编程技术网

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

如何使用R将大型igraph子集为一个节点及其连接的节点?,r,igraph,R,Igraph,我在R中有一个非常大的igraph(称为g) 我只对一个节点(NodeA)以及任何直接连接到NodeA的节点感兴趣。我想以一个非常简单的图形结束,如下图所示 我尝试过子图(g,“nodeA”),但我最终只得到了nodeA本身 我想我需要将图g的边子集为那些连接到节点A的边,然后使用subgraph.edges()。我不知道如何根据边连接到的节点对边进行子集划分 尝试使用邻居() #示例图 g1?如果订单=1,则生成自我图形应执行此操作: g <- make_graph(c(1, 2, 2,

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

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

我尝试过子图(g,“nodeA”),但我最终只得到了nodeA本身

我想我需要将图g的边子集为那些连接到节点A的边,然后使用subgraph.edges()。我不知道如何根据边连接到的节点对边进行子集划分

尝试使用
邻居()

#示例图

g1
?如果订单=1,则生成自我图形
应执行此操作:

g <- make_graph(c(1, 2, 2, 3, 3, 4, 5, 6), directed = FALSE)
V(g)$name <- letters[1:6]
g
#IGRAPH  UN-- 6 4 -- 
#+ attr: name (v/c)
#+ edges from 657f0a0 (vertex names):
#[1] a--b b--c c--d e--f

make_ego_graph(g, order=1, nodes=2)
#[[1]]
#IGRAPH UN-- 3 2 -- 
#+ attr: name (v/c)
#+ edges from 69681da (vertex names):
#[1] a--b b--c
g谢谢。此方法(以及LateMail制作下面的ego图的方法)将子设置到相邻节点。我发现邻居方法更容易理解,尽管make_-ego_-graph方法更灵活。我还想消除邻居之间的边缘(如3-4和3-5之间)。为此,我最终使用了上面的邻居方法,然后是delete_edges方法。首先找到感兴趣节点的名称,然后。。。非节点索引
# 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)
g <- make_graph(c(1, 2, 2, 3, 3, 4, 5, 6), directed = FALSE)
V(g)$name <- letters[1:6]
g
#IGRAPH  UN-- 6 4 -- 
#+ attr: name (v/c)
#+ edges from 657f0a0 (vertex names):
#[1] a--b b--c c--d e--f

make_ego_graph(g, order=1, nodes=2)
#[[1]]
#IGRAPH UN-- 3 2 -- 
#+ attr: name (v/c)
#+ edges from 69681da (vertex names):
#[1] a--b b--c