【问题标题】:igraph read.graph adds one vertexigraph read.graph 添加一个顶点
【发布时间】:2012-11-20 12:38:03
【问题描述】:

当我运行这个简单的例子时,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)

这是运行示例后的样子

有人知道为什么会这样吗?这可以吗还是我错过了什么

【问题讨论】:

    标签: r igraph


    【解决方案1】:

    read.edgelist() 需要一个文本文件,其中顶点 ID 从零开始。如果要将矩阵中的边列表写入文件,请减去 1:

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

    【讨论】:

      【解决方案2】:

      我认为您通过写出文本并重新读入来引入一些错误。 你可以这样做:

      edges <- rbind(c(1,2), c(2,3))
      g <- graph.edgelist(edges)
      plot(g)
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-03-13
        • 1970-01-01
        • 1970-01-01
        • 2013-04-15
        • 2019-01-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多