r - 将顶点属性数据从 igraph 移动到矩阵
问题描述
我计算了 igraph 中一些网络数据的中心性统计数据,我需要两件事的帮助(我认为)。
首先,我想将顶点名称 ( V(g)$name
) 和我计算的新中心度度量 ( (V(g)$eigen
) 从 igraph 中移出到数据框中。
这是我图表中$names
and的第一行。$eigen
$names: year young head black cent call
$eigen: 0.043284327 0.017877101 0.015949110 0.022489540 0.047533029 0.035666735
我想出了下面的代码,但它只是提取顶点名称,不包括(V(g)$eigen
我计算的统计数据。
其次,一旦我在数据框中拥有两列,我希望数据框按(V(g)$eigen
统计数据排序,最大值显示在顶部。
#assigning eigenvector value to vertices
V(subnet)$eigen = eigen_centrality(subnet, weights = E(subnet)$weight)
#export two-column vector (vertex name, centrality)
subnet_matrix <- as.matrix(c(V(subnet)$name), V(subnet)$eigen)
#create new data frame with just those two columns
subnet_df = as.data.frame(subnet_matrix)
#sort df by the centrality value (biggest at top)
sort.list(subnet_df$eigen)
我希望它最终看起来像这样(在数据框中):
NAME EIGEN
cent 0.047533029
year 0.043284327
call 0.035666735
black 0.022489540
young 0.017877101
head 0.015949110
任何帮助将不胜感激。我是 R 和一般编码的新手,所以我一直坚持这种方式太久了。
解决方案
推荐阅读
- c# - 由于 Entity 中的“必需”导航属性,ModelState.IsValid 为 false
- c++ - 拥有一个不使用 Qt 类但使用 Qt 视图的模型是否可行?
- sql - 如何使用 >=all 找到最大值?
- reactjs - NGINX 和反应 :net::ERR_ABORTED 404
- ios - Spotify 会话更新问题
- python - 互斥组中的 Python argparse 帮助选项
- ios - 具有数据 URI 和下载属性的锚点在 iOS/Safari 中不起作用
- angular - doc.fromHTML 不是 angular 6 的函数
- css - 我在 Laravel 中的哪里放置我的 css 文件?
- python - Pytorch 的“折叠”和“展开”是如何工作的?