2014-01-20 147 views
4

我有一個igraph圖,並且想簡單地得到每個邊的from_idto_id。例如:igraph從 - 獲得價值

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 

我想要的是讓兩個變量v1v2其中v1 = 3v2 = 1(相當於v1 = 1v2 = 3)。我想對圖E(g)[x], where x is the loop variable中的所有邊進行此操作。有沒有辦法做到這一點?

由於

回答

7

get.edges()回報所有邊緣,get.edge()返回一個邊緣。如果需要遍歷所有邊,請調用get.edges()並遍歷兩列矩陣的所有行,使用apply()或for循環。

4

get.edgelist(g)是你想要的一個,其吐出矩陣像:

#  [,1] [,2] 
#[1,] 3 1 
0

如果g是你的igraph然後嘗試結束(克,ES = E(G))