从linkcomm包中检索二进制交互作为R中的数据帧 [英] Retrieving binary interactions from linkcomm package as a data frame in R

查看:99
本文介绍了从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,其中每个群集都可以列出所有成对的交互器。这些应该是直接的,即它们具有共同的优势。

From the plot you can see the node 6 is present in 3 overlapping clusters: 3, 7 and 8. I am interested to know how to retrieve the direct binary interactions in these clusters as a data frame. Specifically, I would like a data frame with the cluster id as the first column, and the last two columns as "interactor 1" and "interactor 2", where all pairs of interactors can be listed per cluster. These should be direct, i.e. they have an edge in common.

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

Basically I would like something like this:

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

,以此类推。如有可能,我想避免重复,例如6、14、14和6等。

and so on for the other ids. If possible I would like to avoid duplicates such as 6 and 14, 14 and 6 etc.

非常感谢,

Abigail

推荐答案

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

You might be looking for the edges. Note: Use str(lc) to examine what's all included in your object of interest.

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 ...

这篇关于从linkcomm包中检索二进制交互作为R中的数据帧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆