2017-08-30 72 views
0

我正在使用R(v3.4.1)。 我有一個graphml文件的圖形:如何將一個圖中的邊添加到R中的另一個圖中?

g <-read.graph(file = "./proteinLC.graphml",format = "graphml") 

我需要從圖G節點的10%,並把它們繪製米 我試圖做這樣的事情:

m <- add_edges(g, c(sample(1:length(E(g)), length(E(g))*0.1, replace = F))) 

但我得到一個錯誤:

Error: At type_indexededgelist.c:272 : cannot add edges, Invalid vertex id**

我在做什麼錯?

回答

1

儘管你的標題,我不認爲這樣做的方式是添加邊緣。相反,有一個內置函數可以從節點列表中獲取子圖。這是一個例子。

library(igraph) 

## Build some test data 
set.seed(2017) 
G = erdos.renyi.game(200, 0.2) 
plot(G) 

## Too big, want a sample 
Samp = sample(V(G), 0.1*length(V(G))) 
m = induced_subgraph(G, Samp) 
plot(m) 

Sampled graph

相關問題