英文:
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.
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)
答案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
> 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
> ego_size(g1,2)
[1] 5 7 6 7 7 6 5
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论