r - 从linkcomm包中检索二进制交互作为R中的数据框
问题描述
假设我有以下集群:
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 等。
非常感谢,
阿比盖尔
解决方案
您可能正在寻找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 ...
推荐阅读
- c++ - GCC 升级 C++ 后的问题
- android - 如何在 Kotlin 中将 onCharacteristicWrite() 用于 BLE?
- multithreading - Delphi:当与来自另一个线程的数据交互时,如何使 VCL 控件成为线程安全的?
- java - IntelliJ - 解决 Maven 工件
- javascript - 如何使用 JavaScript 附加 HTML 代码?
- xaml - nuget 中的 UWP 样式和主题找不到资源文件
- openapi - Swagger codegen:生成具有正确名称的数组元素
- java - 通过终端使用 jasypt 加密简单字符串
- android - 如何查找 Android 类引入了哪个 API 级别?
- reactjs - 在反应中从另一个钩子调用钩子