如何通过命名图的端点来删除图形中的边?
delete_edges期望边缘数,我不清楚端点和边缘数之间的映射。
library(igraph)
g = make_ring(10)假设我想删除节点7和8与节点9和10之间的顶点。
这样做的一种方法是:
g = delete_edges(g, c(7, 9))但我必须仔细检查E(g)的输出,然后才能确定这些边沿编号为7& 9。
我试着寻找print方法如何将节点映射分配给E(g),但它看起来就像兔子洞。
发布于 2016-12-28 21:24:59
看起来,您可以使用字符串参数来完成这一任务--参见?delete_edges中的第二个示例。
g = delete_edges(g, c("7|8", "9|10"))
g
# IGRAPH U--- 10 8 -- Ring graph
# + attr: name (g/c), mutual (g/l), circular (g/l)
# + edges:
# [1] 1-- 2 2-- 3 3-- 4 4-- 5 5-- 6 6-- 7 8-- 9 1--10显然,c("7|8", "9|10")也被算作edges参数中描述的“边缘序列”。
发布于 2022-07-31 10:40:59
注意:
get.edge.ids(g, c(7,8, 9, 10))将返回边ids 7,9。
delete_edges(g, get.edge.ids(g, c(7,8, 9, 10)))产生预期的结果:
1] 1-- 2 2-- 3 3-- 4 4-- 5 5-- 6 6-- 7 8-- 9 1--10https://stackoverflow.com/questions/41369830
复制相似问题