该tidygraph
软件包非常适合计算网络统计信息。但是,我有一个具有时间维度的网络,我想计算每个网络的网络统计信息(例如中心性)。(例如,计算每个日期的中心度。)
我想有一种方法可以通过 purrr 和 map 来做到这一点,但我正在努力使用确切的语法。任何帮助在这里表示赞赏。下面的 Repex 示例。
library(tidygraph)
library('purrr')
library(dplyr)
library(tidyr)
# example network data with temporal dimension
edges <- tibble(
from = c(1, 2, 2, 3, 4, 1, 2, 3, 4, 4, 4, 2),
to = c(2, 3, 4, 2, 1, 2, 3, 4, 3, 2, 1, 3),
date = c(rep(1,4), rep(2,4), rep(3,4))
)
nodes <- tibble(id = 1:4)
# calculate centrality over all time periods of network
graph <-
tbl_graph(
nodes = nodes,
edges = edges,
directed = FALSE
)
graph_out <-
graph %>%
mutate(cent_alpha = centrality_alpha()))
# calculate centrality for each time period of the network?
edges_list <-
split(edges, edges$date)
# this doesn't work for me
graph_list <-
lmap(edges_list,
~ tbl_graph(nodes = nodes, edges = .x, directed = FALSE))
## Yikes... no idea
graph_out <-