The problem is when I try to apply a dplyr::mutate function in order to get some measures of centrality to a List of network graphs, iterating thorugh them. I am working with tidygraph.
If I subsett one of the networks of the list, the code works well, my problem is when I try to do it over the whole list. So it is probably somehting related to MAP or LAPPLY functions while iterating over a tbl graph.
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
I get this error message with many different mapping fuctions I have tried so far, such as map, lmap, lapply, sapply, modify, etc.
Thanks!