1
我想要得到圖中所有周期的子圖。我想下面igraph包中的子圖出錯
for (i in 1:length(cycles)){
vids<-as.numeric(unlist(cycles[[i]]))
subgraph<- induced.subgraph(graph, vids)
}
的代碼,但它引發和錯誤如下:
Error in .Call("R_igraph_induced_subgraph", graph, vids - 1, impl, PACKAGE = "igraph") :
At iterators.c:759 : Cannot create iterator, invalid vertex id, Invalid vertex id
我發現代碼與在cycles
列表,它是短,但不是第一個第二個元素。 所以,如果我嘗試這會工作,
subgraph<- induced.subgraph(g, c(3,4))
但不
subgraph<- induced.subgraph(g, c(26, 2, 30, 29, 25, 9, 27, 13, 14, 8, 23, 20, 19, 17, 12, 11, 24, 21, 6, 28, 15,3,4))
此外,任何建議替代for循環的歡迎。
重複的例子:
library(igraph)
graph<-graph(c(1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15,16,
16,17,17,18,18,19,19,20,20,21,21,1,22,23,23,22),directed=T)
V(graph)$name<-c(26, 2, 30, 29, 25, 9, 27, 13, 14, 8, 23, 20, 19, 17, 12, 11,
24, 21, 6, 28, 15,3,4)
cycles<-list(list(26L, 2L, 30L, 29L, 25L, 9L, 27L, 13L, 14L, 8L, 23L,
20L, 19L, 17L, 12L, 11L, 24L, 21L, 6L, 28L, 15L), list(4L,
3L))