r - 如何修复tidygraph中的 “function should not be called directly”错误?

标签 r error-handling dplyr igraph tidygraph

问题是,当我尝试应用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/

相关文章:

r - 如何在shiny或flexdashboard中制作用户选择的变量的图表?

r - 将 mutate_at 与 mutate_if 一起使用

r - Mutate 以错误的顺序返回数据 dplyr 这是一个错误吗?

Polycharts 热图 rCharts 中的重新排序因子

r - 提取行 r 之间的数据

r - 保存 RGLplot3d() 图的方向

r - if else 语句和 if_else 的不同行为

matlab - 如果用户输入了错误的输入,如何退出 matlab m 文件(不是 matlab 本身)?

swift - NSSetUncaughtExceptionHandler 在 Swift 3 中没有触发?

error-handling - CUSTOMTAB_IS_INCOMPLETE是什么意思?