【问题标题】:Preparing data for Gephi为 Gephi 准备数据
【发布时间】:2018-01-03 14:38:13
【问题描述】:

问候,

我需要为 Gephi 中的网络分析准备数据。我有以下格式的数据:

MY Data

我需要格式的数据(其中的值代表通过组织连接的人员):

Required format

非常感谢!

【问题讨论】:

    标签: r reshape gephi network-analysis


    【解决方案1】:

    我认为这段代码应该可以完成这项工作。这不是最好的最优雅的方式,但它有效:)

    # Data
    x <-
      structure(
        list(
          Persons = c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L),
          Organizations = c("A", "B", "E", "F", "A", "E", "C", "D", "C", "A", "E")
        ),
        .Names = c("Persons", "Organizations"),
        class = "data.frame",
        row.names = c(NA, -11L)
      )
    
    # This will merge n:n
    edgelist <- merge(x, x, by = "Organizations")[,2:3]
    
    # We don't want autolinks
    edgelist <- subset(edgelist, Persons.x != Persons.y)
    
    # Removing those that are repeated
    edgelist <- unique(edgelist)
    
    edgelist
    #>   Persons.x Persons.y
    #> 2         1         3
    #> 3         1         2
    #> 4         3         1
    #> 6         3         2
    #> 7         2         1
    #> 8         2         3
    

    reprex package (v0.1.1.9000) 于 2018 年 1 月 3 日创建。

    【讨论】:

      【解决方案2】:

      x开头:

      structure(list(Persons = c(1L, 1L, 1L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L), Organizations = c("A", "B", "E", "F", "A", "E", "C", "D", "C", "A", "E")), .Names = c("Persons", "Organizations"), class = "data.frame", row.names = c(NA,-11L))
      

      创建一个具有不同名称的新data.frame。只需将Organizations 转换为因子,然后使用数值:

      > y=data.frame(Source=x$Persons, Target=as.numeric(as.factor(x$Organizations)))
      > y
         Source Target
      1       1      1
      2       1      2
      3       1      5
      4       2      6
      5       2      1
      6       2      5
      7       2      3
      8       3      4
      9       3      3
      10      3      1
      11      3      5
      

      不管怎样,我很确定 gephi 可以处理字符串。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2015-04-07
        • 1970-01-01
        • 2017-04-07
        • 2019-05-27
        • 1970-01-01
        • 1970-01-01
        • 2019-05-24
        相关资源
        最近更新 更多