2017-08-30 51 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

相关问题