igraph从 - 获得优势 - 价值

qui*_*ine 5 r igraph

我有一个igraph图,想要简单地得到每个边缘from_idto_id.例如:

g <- erdos.renyi.game(4, 1, type="gnm", directed=FALSE)
E(g)[1] # will return some edge, possibly not the same one
# Edge sequence:
# e       
# e [1] 3 -- 1
Run Code Online (Sandbox Code Playgroud)

我想要的是获得两个变量v1,v2where v1 = 3v2 = 1(相当于v1 = 1v2 = 3).我想对图中的所有边做这个E(g)[x], where x is the loop variable.有没有办法做到这一点?

谢谢

Gab*_*rdi 7

get.edges()返回所有边,get.edge()返回一条边.如果需要遍历所有边,则调用get.edges()并遍历双列矩阵的所有行apply(),或者使用for循环.


the*_*ail 5

get.edgelist(g) 是您想要的那个,它吐出一个矩阵,如:

#     [,1] [,2]
#[1,]    3    1
Run Code Online (Sandbox Code Playgroud)