【问题标题】:igraph and read.table, isolated vertices in Rigraph 和 read.table,R 中的孤立顶点
【发布时间】:2016-06-07 09:13:41
【问题描述】:

我看到 R 中的 igraph 需要如下结构的数据:

nodeA  nodeB   int_1 int_2
AA      BD      6   X   
BD      CA      8   Y
AA      DE      7   Y
...     ...     ... ...

我通过

看到了这一点
data<-read.table(file)
graph.data.frame(data)

我获取了对应的网络。

现在说我必须放置隔离节点,我在文档中进行了搜索,但找不到任何可以回答我问题的内容。

如何在原始文件中指定它们?

我想到了类似的东西(比如 .sif 格式)

nodeA  nodeB   int_1 int_2
AA      DE      7   Y
...     ...     ... ...
isoNodeA
isoNodeB
...

但显然 read.table 不接受行之间不同数量的字段。

【问题讨论】:

    标签: r networking graph igraph rscript


    【解决方案1】:

    你可以这样试试:

    data<-read.table(header=T, fill = TRUE, stringsAsFactors=F, text="
    nodeA  nodeB   int_1 int_2
    AA      BD      6   X   
    BD      CA      8   Y
    AA      DE      7   Y
    ZZ
    DE      BD      7   Y")
    data[data==""] <- NA
    
    library(igraph)
    g <- graph.data.frame(
      data[complete.cases(data),], 
      vertices = unique(na.omit(unlist(data[1:2]))))
    plot(g)
    

    【讨论】:

      猜你喜欢
      • 2020-11-02
      • 1970-01-01
      • 2017-07-29
      • 2015-07-21
      • 2013-01-21
      • 2017-10-19
      • 2018-04-14
      • 2015-11-20
      • 1970-01-01
      相关资源
      最近更新 更多