图的阶数 n

huangapple go评论92阅读模式
英文:

Degree of order n of a graph

问题

I'd like to calculate the number of adjacent edges in an extra step of the degree() function. This would be a degree() of order 2, for example.

For example, the graph on the left illustrates the classic degree() function, but I'm looking for an additional level of degree() (graph on the right). The degree() of vertex "1" corresponds to 2 but the additional level is 5. Is there a way of calculating this degree of order n for each vertex?

Code:
g1 <- graph(edges=c(1,2,1,3,2,3,3,5,2,4,4,5,5,6,4,6,4,7,6,7),n=7,directed=F)
plot(g1)

英文:

I'd like to calculate the number of adjacent edges in an extra step of the degree() function. This would be a degree() of order 2, for example.
图的阶数 n

For example, the graph on the left illustrates the classic degree() function, but I'm looking for an additional level of degree() (graph on the right). The degree() of vertex "1" corresponds to 2 but the additional level is 5. Is there a way of calculating this degree of order n for each vertex?

Code:
g1 &lt;- graph(edges=c(1,2,1,3,2,3,3,5,2,4,4,5,5,6,4,6,4,7,6,7),n=7,directed=F)
plot(g1)

答案1

得分: 1

我猜你可以尝试使用 ego 函数:

> ego(g1, 2)
[[1]]
+ 5/7 vertices, from 47df27b:
[1] 1 2 3 4 5

[[2]]
+ 7/7 vertices, from 47df27b:
[1] 2 1 3 4 5 6 7

[[3]]
+ 6/7 vertices, from 47df27b:
[1] 3 1 2 5 4 6

[[4]]
+ 7/7 vertices, from 47df27b:
[1] 4 2 5 6 7 1 3

[[5]]
+ 7/7 vertices, from 47df27b:
[1] 5 3 4 6 1 2 7

[[6]]
+ 6/7 vertices, from 47df27b:
[1] 6 4 5 7 2 3

[[7]]
+ 5/7 vertices, from 47df27b:
[1] 7 4 6 2 5

或者 ego_size 函数:

> ego_size(g1,2)
[1] 5 7 6 7 7 6 5
英文:

I guess you can try ego

&gt; ego(g1, 2)
[[1]]
+ 5/7 vertices, from 47df27b:
[1] 1 2 3 4 5

[[2]]
+ 7/7 vertices, from 47df27b:
[1] 2 1 3 4 5 6 7

[[3]]
+ 6/7 vertices, from 47df27b:
[1] 3 1 2 5 4 6

[[4]]
+ 7/7 vertices, from 47df27b:
[1] 4 2 5 6 7 1 3

[[5]]
+ 7/7 vertices, from 47df27b:
[1] 5 3 4 6 1 2 7

[[6]]
+ 6/7 vertices, from 47df27b:
[1] 6 4 5 7 2 3

[[7]]
+ 5/7 vertices, from 47df27b:
[1] 7 4 6 2 5

or ego_size

&gt; ego_size(g1,2)
[1] 5 7 6 7 7 6 5 

huangapple
  • 本文由 发表于 2023年6月15日 21:22:57
  • 转载请务必保留本文链接:https://go.coder-hub.com/76482953.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定