问题是,当我尝试应用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等。
谢谢!
最佳答案
要在不映射的情况下计算学位中心度,您需要激活节点
Networklist %>%
activate(nodes) %>%
mutate(degreein = centrality_degree(weights = NULL, mode = "in", loops=FALSE, normalized=FALSE)
如果要将其添加为属性,则将其分配回Networklist。
关于r - 如何修复tidygraph中的 “function should not be called directly”错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57566119/