问题是当我尝试应用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等。
谢谢!
答案 0 :(得分:0)
要计算没有映射的学位中心度,您需要激活节点
Networklist %>%
activate(nodes) %>%
mutate(degreein = centrality_degree(weights = NULL, mode = "in", loops=FALSE, normalized=FALSE)
如果要将其添加为属性,则将其分配回Networklist。