R 如何在图形对象上使用max_cliques()后追加所有子列表编号
我有一个R 如何在图形对象上使用max_cliques()后追加所有子列表编号,r,igraph,R,Igraph,我有一个igraph对象,它是我用以下内容创建的: g3 <- graph.data.frame(DF.WORK.EDGE, directed=TRUE, vertices=DF.WORK.VERTEX) 当然,我得到了一长串不同派系的子名单: 这个列表不停地列出,我需要找出哪个节点出现得最频繁(重叠最多),这样我就知道哪个节点在不同的子集团中 如果没有add hoc函数来汇总这些值的频率,有人能告诉我如何检索所有子列表并将它们连接到同一个列表中吗?我正在考虑在那之后做一个汇总
igraph
对象,它是我用以下内容创建的:
g3 <- graph.data.frame(DF.WORK.EDGE, directed=TRUE, vertices=DF.WORK.VERTEX)
当然,我得到了一长串不同派系的子名单:
这个列表不停地列出,我需要找出哪个节点出现得最频繁(重叠最多),这样我就知道哪个节点在不同的子集团中
如果没有add hoc函数来汇总这些值的频率,有人能告诉我如何检索所有子列表并将它们连接到同一个列表中吗?我正在考虑在那之后做一个汇总表,看看在所有子列表中哪个数字显示得最多。谢谢
让我们随机分成10组:
set.seed(42)
n_集团
#> [[2]]
#> [1] 42 37 39 19 32 1 49 45 9 38 25 15 17 2 36 16 33 30
#>
#> [[3]]
#> [1] 32 48 30 16 47 18
将它们放入数据框:
d团顶点
#> 1 1 23
#> 2 1 36
#> 3 1 45
#> 4 1 13
#> 5 1 22
#> 6 1 43
顶点30出现在7个团中:
排序(表(d$vertex),递减=真)[1:10]
#>
#> 30 1 32 36 38 37 50 8 11 14
#> 7 5 5 5 5 4 4 3 3 3
以下是7个派系:
子集(d,顶点==30)$clique
#> [1] 1 2 3 4 6 7 9
让我们随机分成10组:
set.seed(42)
n_集团
#> [[2]]
#> [1] 42 37 39 19 32 1 49 45 9 38 25 15 17 2 36 16 33 30
#>
#> [[3]]
#> [1] 32 48 30 16 47 18
将它们放入数据框:
d团顶点
#> 1 1 23
#> 2 1 36
#> 3 1 45
#> 4 1 13
#> 5 1 22
#> 6 1 43
顶点30出现在7个团中:
排序(表(d$vertex),递减=真)[1:10]
#>
#> 30 1 32 36 38 37 50 8 11 14
#> 7 5 5 5 5 4 4 3 3 3
以下是7个派系:
子集(d,顶点==30)$clique
#> [1] 1 2 3 4 6 7 9
您只需取消列表
和表格
集团
set.seed(8675309) ##Sets the random number generator so that results are exactly reproducible.
g <- graph_from_edgelist(matrix(sample(LETTERS[1:10], 50, replace=T), ncol = 2), directed = FALSE) ##made a random graph
cliques <- max_cliques(g) ##Find maximal cliques
#cliques is a list of vectors containing nodes
#unlist turns the list into one vector,
#a side effect of unlist is that the node ID is returned not the node
#name (in this case A-J) so we use the names function to grab the node names.
#Lastly table tabulates the data, in this case counts the instances of each node in the vector. table could be replaced by tapply, or any other number of function.
nodeCliques <- table(names(unlist(cliques)))
#To get the nodes that are in the most cliques we subset the table based on the max number of cliques the nodes are in.
nodeCliques[which(nodeCliques==max(nodeCliques))]
# H I
# 4 4
set.seed(8675309)##设置随机数生成器,使结果完全可重复。
g您可以取消列出和表格集团
set.seed(8675309) ##Sets the random number generator so that results are exactly reproducible.
g <- graph_from_edgelist(matrix(sample(LETTERS[1:10], 50, replace=T), ncol = 2), directed = FALSE) ##made a random graph
cliques <- max_cliques(g) ##Find maximal cliques
#cliques is a list of vectors containing nodes
#unlist turns the list into one vector,
#a side effect of unlist is that the node ID is returned not the node
#name (in this case A-J) so we use the names function to grab the node names.
#Lastly table tabulates the data, in this case counts the instances of each node in the vector. table could be replaced by tapply, or any other number of function.
nodeCliques <- table(names(unlist(cliques)))
#To get the nodes that are in the most cliques we subset the table based on the max number of cliques the nodes are in.
nodeCliques[which(nodeCliques==max(nodeCliques))]
# H I
# 4 4
set.seed(8675309)##设置随机数生成器,使结果完全可重复。
非常感谢,这是简洁和有益的!请您解释一下nodeclikes是如何感谢您的,这是一个非常彻底的解释!非常感谢,这是简洁和有益的!请您解释一下nodeclikes是如何感谢您的,这是一个非常彻底的解释!我可以知道这里的x=50是什么意思吗,在sample(x=50,团大小[I])
中?它意味着我要从1:50
的间隔中采样group大小[I]
的数字。更多细节参见:也考虑运行代码看看发生了什么。我可以知道x=50是什么意思吗?在<代码>示例中(x=50,cLimiStudioSt[i])< /代码>?这意味着我想从区间<代码> 1:50中采样<代码> CbILILYSIZ[I] <代码>编号。查看更多细节:也考虑运行代码看看发生了什么。