【问题标题】:Retrieving binary interactions from linkcomm package as a data frame in R从linkcomm包中检索二进制交互作为R中的数据框
【发布时间】:2020-09-05 21:37:37
【问题描述】:

假设我有以下集群:

library(linkcomm)
g <- swiss[,3:4]
lc <-getLinkCommunities(g)
plot(lc, type = "members")
getNodesIn(lc, clusterids = c(3, 7, 8))

从图中您可以看到节点 6 存在于 3 个重叠的集群中:3、7 和 8。我很想知道如何将这些集群中的直接二进制交互作为数据框检索。具体来说,我想要一个数据框,其中集群 id 作为第一列,最后两列作为“交互器 1”和“交互器 2”,其中可以列出每个集群的所有交互器对。这些应该是直接的,即它们具有共同的优势。

基本上我想要这样的东西:

Cluster ID   Interactor 1  Interactor 2
3               6                14
3               3                7
3               6                7
3               14               3
3               6                3

其他 id 依此类推。如果可能的话,我想避免重复,例如 6 和 14、14 和 6 等。

非常感谢,

阿比盖尔

【问题讨论】:

    标签: r dataframe igraph data-manipulation


    【解决方案1】:

    您可能正在寻找edges注意: 使用str(lc) 检查您感兴趣的对象中包含的所有内容。

    lc$edges
    #    node1 node2 cluster
    # 1     17    15       1
    # 2     17     8       1
    # 3     15     8       1
    # 4     16    13       2
    # 5     16    10       2
    # 6     16    29       2
    # 7     14     6       3
    # 8 ...
    
    res <- setNames(lc$edges, c(paste0("interactor.", 1:2), "cluster"))[c(3, 1, 2)]
    res
    #    cluster interactor.1 interactor.2
    # 1        1           17           15
    # 2        1           17            8
    # 3        1           15            8
    # 4        2           16           13
    # 5        2           16           10
    # 6        2           16           29
    # 7        3           14            6
    # 8 ...
    

    【讨论】:

    • 非常感谢@jay.sf
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多