igraph read.graph添加一个顶点

igraph read.graph添加一个顶点,r,igraph,R,Igraph,当我运行这个简单的示例时,igraph添加一个顶点,我的顶点从2开始,而不是从1开始 # very very simple graph (1-2-3) edges <- rbind(c(1,2), c(2,3)) write.table(edges, file="edgetest.txt", sep=" ", quote=F, row.names=F, col.names = F) g <- simplify(read.graph(file="edgetest.txt", form

当我运行这个简单的示例时,igraph添加一个顶点,我的顶点从2开始,而不是从1开始

# very very simple graph (1-2-3)
edges <- rbind(c(1,2), c(2,3))

write.table(edges, file="edgetest.txt", sep=" ", quote=F, row.names=F, col.names = F)
g <- simplify(read.graph(file="edgetest.txt", format="edgelist", directed=F))
plot(g)
#非常简单的图形(1-2-3)

边缘我认为你写下文本并重新阅读是在引入一些错误。 你可以这样做:

edges <- rbind(c(1,2), c(2,3))
g <- graph.edgelist(edges)
plot(g)
edges
read.edgelist()
需要一个文本文件,其中顶点ID从零开始。如果要将矩阵中的边列表写入文件,请减去1:

write.table(edges-1, file="edgetest.txt", sep=" ", 
            quote=F, row.names=F, col.names = F)