问题是,当我试图应用dplyr::mutate函数以获得网络图列表的一些中心性度量时,对它们进行迭代。我正在使用tidygraph。
如果我子集化列表中的一个网络,代码工作得很好,我的问题是当我试图对整个列表进行子集化时。因此,在tbl图上迭代时,它可能与MAP或LAPPLY函数有关。
library (tidyverse)
library (tidygraph)
#My df has the following characteristics
>df
origin destination year amount
1 Colombia Brasil 2005 16
2 Colombia US 2005 50
3 Colombia Argentina 2005 0
4 Colombia France 2006 5
5 Colombia US 2006 6
6 Brasil US 2005 5
7 Brasil Argentina 2005 7
8 Brasil France 2006 8
9 Argentina France 2005 0
10 Argentina US 2005 10
11 Argentina France 2006 5
#This is how I get the network graph list.
Networklist <- df %>%
filter(amount>0) %>%
group_by(year) %>%
group_map(as_tbl_graph)
#Then I apply the functions and that's where I get the error message
Networklist %>%
map(mutate(degreein = centrality_degree(weights = NULL, mode = "in", loops=FALSE, normalized=FALSE))
#Error: this function should not be called directly到目前为止,我已经尝试过许多不同的映射函数,例如map、lmap、lapply、sapply、modify等,我都收到了这个错误消息。
谢谢!
发布于 2020-08-13 01:19:48
要在不映射的情况下计算度中心度,需要激活节点
Networklist %>%
activate(nodes) %>%
mutate(degreein = centrality_degree(weights = NULL, mode = "in", loops=FALSE, normalized=FALSE)如果您想将其作为属性添加,则将其分配回Networklist。
https://stackoverflow.com/questions/57566119
复制相似问题