[英]How to delete vertices in graph in R?
因為給出的一個頂點不在圖形頂點列表中,所以會出現錯誤。 一個建議嘗試使用igraph
函數,一旦您熟悉它們,就將其應用於自定義圖形。 這里有一個示范:
library(igraph)
g <- graph.ring(10)
V(g)
Vertex sequence:
[1] 1 2 3 4 5 6 7 8 9 10
現在,我嘗試刪除現有的頂點:
delete.vertices(g, c(2,7,9) )
IGRAPH U--- 7 4 -- Ring graph
+ attr: name (g/c), mutual (g/x), circular (g/x)
對於不存在的錯誤,我得到您的錯誤:
delete.vertices(g, c(20))
Error in delete.vertices(g, c(20)) :
At iterators.c:759 : Cannot create iterator, invalid vertex id, Invalid vertex id
您正在使用Igraph嗎?
read.graph函數可能正在以字符串形式讀取頂點ID。 在這種情況下,您可能需要:
delete.vertices(graph,c('717527','61373'))
代替。 同樣,delete.verticies返回一個新的圖形對象。 如果要查看更改后的結果,請確保將結果存儲在圖形中。
graph<-read.graph(paste0("H:/graph.txt"),format="ncol",directed="TRUE")
graph<-delete.vertices(graph,c('717527','61373'))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.