R iGraph:双向边情况下的度数

R iGraph: degree in the case of bidirectional edges

我注意到,只要涉及双向边,iGraph 中的函数 degree 就不能直接计算有向图的无向骨架图的度数。 例如,

g <-graph_from_literal( a-+b,a++c,d-+a,a-+e,a-+f )

d1 <- degree(g,v='a',mode="all")
# 6
nn <- unique(neighbors(g,'a',mode='all'))
d2 <- length(nn)
# 5

正如我想要的那样 d2,而不是 d1,我使用了基于查找所考虑顶点的邻居的不同路线。 我的问题是:是否有 better/faster 方法可以做到这一点,也许使用其他一些我不知道的 iGraph 函数?

创建图的无向副本,将无向图中的多条边折叠成一条边,然后计算其度数:

> g2 <- as.undirected(g, mode="collapse")
> degree(g2)