gpt4 book ai didi

r - 图,r : unlist node centrality scores for a list of matrices

转载 作者:行者123 更新时间:2023-12-04 18:00:22 26 4
gpt4 key购买 nike

我正在处理我正在使用 igraph 包分析的网络图列表(即 1000 多个邻接矩阵)。这些图存储在一个拆分文件中,每个图都有一个唯一的 ID。

我使用以下代码计算了各个节点在各个图中的中介中心性分数:

b <- function (b) betweenness(b, directed = FALSE, normalized = TRUE)
Between <- lapply (listofgraphs, b)

show(Between) #looks like this:

$`35630` #Graph ID
1676 1741 1750 #Node ID
0 1 0 #Scores

$`35631`
1738 1750
0 1

$`35633`
1738 1750 4110
0 0 0

现在,我需要的是一个数据框,其中包含图 ID、节点 ID 的列和中间值的各个分数。像这样:

Graph.ID    Node.ID    Betweenness
35630 1676 0
35630 1741 1
35630 1759 0
35631 1738 0
35631 1750 1
35631 1738 0
35633 1750 0
35633 et cetera .....

我试过 unlist、rbind 等,但出于某种原因我无法让它工作。如果有人能帮我解决这个问题,那就太棒了!

最佳答案

stack list< 中的命名 vector 之后,我们可以melt list/

library(reshape2)
melt(lapply(Between, stack))[-2]

关于r - 图,r : unlist node centrality scores for a list of matrices,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36238377/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com