如何根据时间序列数据在 R 中创建网络列表

How to create a list of Networks in R based on Time Series Data

我正在尝试查看时间序列中的个人网络和站点访问。本质上,我想要实现的最终结果类似于包 "dnr" 中的 "beaches" 数据集。我有一个更大的数据集输出,其中的一个子集显示在底部。

基本上我想 split() 这个 table 通过 SpeciesWeek 然后创建一个关联矩阵,其中包含来自 [=19= 的不同值的行] 和基于 SiteVisits 中不同值的列。然后我每周使用包 igraphgraph_from_incidence_matrix 为每个物种创建一个独特的网络。

我开始尝试按物种拆分主要 table,然后每周为每个物种创建新的 table:

DFsplit <- split(DF, DF$Species)
DFsplit_cf <- split(DFsplit$Catfish, DFsplit$Catfish$Week)

这工作正常,但是当我尝试编写一个循环来使用此数据帧构建网络时

network_builder <- function(data) {
  for(i in 1: length(data)) {
    adjacency <- xtabs(~ data[[i]][,3] + data[[i]][,4])
    network[i] <- graph_from_incidence_matrix(adjacency)
  }
}

network_builder(DFsplit_stb)

我收到了

 Error in model.frame.default(formula = ~data[[i]][, 3] + data[[i]][, 4]) : 
  invalid type (list) for variable 'data[[i]][, 3]' 

我猜想有办法解决这个错误,但我试过的都没有用。另外,如果有更简洁的方法来做到这一点,我会洗耳恭听。

输出:

structure(list(Species = c("Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Largemouth Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Catfish", "Catfish", "Catfish", 
"Catfish", "Catfish", "Catfish", "Catfish", "Catfish", "Catfish", 
"Catfish", "Catfish", "Catfish", "Catfish", "Catfish", "Catfish", 
"Catfish", "Catfish", "Catfish", "Catfish", "Catfish", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Largemouth Bass", "Largemouth Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Largemouth Bass", 
"Largemouth Bass", "Largemouth Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass", "Striped Bass", "Striped Bass", 
"Striped Bass", "Striped Bass"), Week = c(74, 74, 75, 76, 77, 
77, 77, 77, 77, 77, 78, 78, 79, 79, 79, 79, 79, 79, 79, 80, 80, 
80, 80, 81, 83, 83, 83, 83, 83, 84, 84, 84, 84, 84, 85, 85, 85, 
85, 85, 86, 86, 86, 86, 87, 88, 89, 90, 91, 92, 92, 92, 93, 93, 
93, 93, 93, 94, 94, 94, 95, 95, 95, 95, 95, 96, 96, 96, 96, 96, 
96, 96, 96, 97, 97, 97, 97, 98, 99, 99, 99, 99, 99, 100, 101, 
101, 101, 101, 101, 101, 101, 101, 102, 103, 103, 103, 103, 103, 
104, 104, 104, 104, 105, 105, 105, 105, 106, 106, 106, 106, 107, 
107, 107, 107, 108, 109, 110, 54, 54, 55, 55, 55, 56, 56, 56, 
57, 57, 57, 58, 60, 60, 60, 61, 61, 68, 68, 68, 69, 70, 70, 71, 
72, 73, 74, 74, 75, 76, 76, 77, 78, 78, 79, 80, 80, 81, 84, 86, 
86, 87, 88, 89, 90, 90, 91, 91, 92, 92, 93, 93, 94, 97, 97, 98, 
98, 98, 100, 100, 100, 101, 101, 101, 103, 103, 103, 164, 165, 
165, 165, 165, 166, 166, 166, 167, 168, 168, 168, 57, 58, 58, 
59, 60, 61, 61, 61, 62, 62, 63, 63, 63, 66, 70, 71, 74, 75, 76, 
76, 76, 76, 77, 78, 79, 80, 81, 82, 83, 84, 84, 20, 6, 7, 8, 
8, 8, 9, 9, 9, 10, 10, 10, 11, 11, 11, 12, 12, 12, 13, 13, 13, 
14, 14, 14, 15, 15, 16, 16, 17, 17, 17, 204, 204, 204, 205, 205, 
206, 206, 206, 207, 207, 207, 208, 208, 208, 209, 209, 209, 210, 
216, 228, 233, 233, 233, 234, 235, 236, 237, 239, 239, 240, 241, 
241, 242, 242, 243, 244, 244, 244, 245, 245, 64, 64, 64, 65, 
66, 67, 68, 69, 70, 71, 72, 72, 73, 73, 73, 74, 75, 76, 76, 76, 
77, 77, 77, 78, 78, 78, 79, 79, 79, 79, 80, 80, 81, 81, 83, 83, 
83, 84, 84, 84, 85, 86, 86, 87, 94, 95, 97, 97, 97, 97, 98, 99, 
99, 99, 100, 102, 103, 103, 103, 105, 106, 107, 107, 107, 107, 
108, 108, 108, 108, 109, 109, 109, 110, 110, 110, 110, 111, 111, 
111, 111, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 
98, 99, 100, 101, 102, 102, 102, 153, 154, 155, 156, 157, 158, 
159, 160, 161, 161, 161, 162, 162, 163, 163, 163, 164, 165, 166, 
49, 14, 14, 185, 47, 74, 74, 75, 75, 75, 76, 76, 76, 78, 78, 
78, 79, 80, 81, 82, 83, 83, 84, 84, 85, 85, 3, 3, 146, 147, 148, 
149, 149, 149, 150, 150, 150, 150, 150, 150, 109, 77, 78, 79, 
20, 20, 21, 21, 21, 22, 22, 22, 23, 23, 23, 23, 24, 25, 26, 27, 
27, 40, 40, 40, 40, 41, 41, 45, 45, 45, 50, 50, 50, 52, 52, 52, 
45, 45, 45, 46, 46, 46, 48, 48), TagID = c(5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 5004.24, 
5004.24, 5004.24, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 
5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5010.04, 5011.03, 
5011.03, 5011.03, 5011.03, 5011.03, 5011.03, 5011.03, 5011.03, 
5011.03, 5011.03, 5011.03, 5011.03, 5011.07, 5011.07, 5011.07, 
5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 
5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 
5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 
5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 5011.07, 
5017.06, 5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 
5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 
5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 
5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 5025.22, 
5025.22, 5025.22, 5025.22, 5025.26, 5025.26, 5025.26, 5025.26, 
5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 
5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 
5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 
5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 
5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 5025.26, 
5025.26, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 5032.24, 
5032.24, 5032.24, 5032.24, 5032.24, 5038.04, 5038.04, 5038.04, 
5038.04, 5038.04, 5038.04, 5038.04, 5038.04, 5038.04, 5038.04, 
5038.04, 5038.04, 5038.04, 5038.04, 5038.04, 5038.04, 5038.04, 
5038.04, 5038.04, 5038.04, 5039.03, 5039.03, 5039.03, 5039.03, 
5039.03, 5039.03, 5039.03, 5039.03, 5039.03, 5039.03, 5039.03, 
5039.03, 5039.03, 5039.03, 5039.03, 5039.03, 5039.03, 5039.03, 
5039.03, 5039.07, 5045, 5045, 5053.26, 5066.04, 5067.07, 5067.07, 
5067.07, 5067.07, 5067.07, 5067.07, 5067.07, 5067.07, 5067.07, 
5067.07, 5067.07, 5067.07, 5067.07, 5067.07, 5067.07, 5067.07, 
5067.07, 5067.07, 5067.07, 5067.07, 5067.07, 5073.06, 5073.06, 
5074.16, 5074.16, 5074.16, 5074.16, 5074.16, 5074.16, 5074.16, 
5074.16, 5074.16, 5074.16, 5074.16, 5074.16, 5088.11, 5094.04, 
5094.04, 5094.04, 5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 
5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 
5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 
5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 
5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 5101.06, 5116.24, 
5116.24, 5116.24, 5116.24, 5116.24, 5116.24, 5116.24, 5116.24
), SiteVisits = c("IC1", "RGD1", "RGD1", "RGD1", "RGD1", "RGU1", 
"ORS1", "WC1", "WC2", "WC3", "WC2", "WC3", "IC3", "RGD1", "RGU1", 
"ORS1", "WC1", "WC2", "WC3", "RGD1", "RGU1", "WC2", "WC3", "WC3", 
"RGU1", "ORS1", "WC1", "WC2", "WC3", "RGU1", "ORS1", "WC1", "WC2", 
"WC3", "RGU1", "ORS1", "WC1", "WC2", "WC3", "RGD1", "RGU1", "ORS1", 
"WC1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "IC3", "IC1", 
"RGD1", "RGD1", "RGU1", "ORS1", "WC1", "WC2", "RGU1", "ORS1", 
"WC1", "RGU1", "ORS1", "WC1", "WC2", "WC3", "IC3", "IC1", "RGD1", 
"RGU1", "ORS1", "WC1", "WC2", "WC3", "RGD1", "WC1", "WC2", "WC3", 
"WC3", "RGD1", "RGU1", "WC1", "WC2", "WC3", "RGD1", "IC3", "IC2", 
"IC1", "RGD1", "RGU1", "WC1", "WC2", "WC3", "WC3", "RGD1", "RGU1", 
"WC1", "WC2", "WC3", "IC3", "IC2", "IC1", "RGD1", "IC3", "IC2", 
"IC1", "RGD1", "IC3", "IC2", "IC1", "RGD1", "IC3", "IC2", "IC1", 
"RGD1", "RGD1", "RGD1", "RGD1", "IC2", "IC1", "IC3", "IC2", "IC1", 
"IC3", "IC2", "IC1", "IC3", "IC2", "IC1", "IC1", "IC3", "IC2", 
"IC1", "IC2", "IC1", "IC3", "IC2", "IC1", "IC2", "IC3", "IC2", 
"IC1", "IC1", "IC1", "IC3", "IC1", "IC1", "IC3", "IC1", "IC1", 
"IC1", "RGD1", "RGD1", "IC3", "RGD1", "IC3", "IC2", "IC2", "IC1", 
"IC1", "IC1", "IC1", "IC3", "IC1", "IC3", "IC1", "IC3", "IC1", 
"IC3", "IC1", "IC1", "IC3", "IC1", "IC3", "IC2", "IC1", "IC3", 
"IC2", "IC1", "IC3", "IC2", "IC1", "IC3", "IC2", "IC1", "RGD1", 
"IC3", "IC2", "IC1", "RGD1", "IC3", "IC2", "IC1", "RGD1", "IC2", 
"IC1", "RGD1", "IC1", "IC1", "RGD1", "IC1", "IC1", "IC3", "IC2", 
"IC1", "IC3", "IC1", "IC3", "IC2", "IC1", "RGD1", "RGD1", "RGD1", 
"RGD1", "RGD1", "IC3", "IC2", "IC1", "RGD1", "RGD1", "IC1", "RGD1", 
"RGD1", "RGD1", "RGD1", "RGD1", "IC2", "RGD1", "IC1", "IC1", 
"RGD1", "IC3", "IC2", "IC1", "IC3", "IC2", "IC1", "IC3", "IC2", 
"IC1", "IC3", "IC2", "IC1", "IC3", "IC2", "IC1", "IC3", "IC2", 
"IC1", "IC3", "IC2", "IC1", "IC3", "IC2", "IC3", "IC2", "IC3", 
"IC2", "IC1", "IC3", "IC2", "IC1", "IC3", "IC2", "IC3", "IC2", 
"IC1", "IC3", "IC2", "IC1", "IC3", "IC2", "IC1", "IC3", "IC2", 
"IC1", "IC1", "IC1", "IC1", "IC3", "IC2", "IC1", "IC1", "IC1", 
"IC1", "IC1", "IC2", "IC1", "IC1", "IC2", "IC1", "IC2", "IC1", 
"IC1", "IC3", "IC2", "IC1", "IC2", "IC1", "IC3", "IC2", "RGD1", 
"RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "IC1", 
"RGD1", "IC2", "IC1", "RGD1", "RGD1", "RGD1", "IC3", "IC1", "RGD1", 
"IC3", "IC2", "IC1", "IC3", "IC2", "IC1", "IC3", "IC2", "IC1", 
"RGD1", "IC3", "RGD1", "IC3", "RGD1", "IC3", "IC2", "RGD1", "IC3", 
"IC2", "RGD1", "RGD1", "IC2", "RGD1", "RGD1", "RGD1", "RGD1", 
"IC3", "IC2", "IC1", "RGD1", "RGD1", "IC2", "IC1", "RGD1", "RGD1", 
"IC1", "IC3", "IC2", "IC1", "RGD1", "RGD1", "IC3", "IC2", "IC1", 
"RGD1", "IC3", "IC2", "IC1", "RGD1", "IC3", "IC2", "IC1", "IC3", 
"IC2", "IC1", "RGD1", "IC3", "IC2", "IC1", "RGD1", "RGD1", "RGD1", 
"RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", 
"RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", 
"RGU1", "ORS1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", "RGD1", 
"RGD1", "RGD1", "IC2", "IC1", "RGD1", "IC2", "IC1", "IC2", "IC1", 
"RGD1", "RGD1", "RGD1", "RGD1", "IC1", "IC2", "IC1", "RGD1", 
"IC2", "IC3", "IC1", "IC3", "IC1", "RGD1", "IC2", "IC1", "RGD1", 
"IC3", "IC2", "IC1", "RGD1", "IC3", "IC3", "IC3", "IC3", "IC2", 
"IC3", "IC2", "IC3", "IC2", "IC2", "IC1", "RGD1", "RGD1", "RGD1", 
"RGD1", "RGU1", "ORS1", "RGU1", "ORS1", "WC1", "WC2", "GL1", 
"WC3", "RGD1", "IC1", "IC1", "IC1", "IC3", "IC2", "IC3", "IC2", 
"IC1", "IC3", "IC2", "IC1", "IC3", "IC2", "IC1", "RGD1", "RGD1", 
"RGD1", "RGD1", "RGD1", "RGU1", "ORS1", "WC1", "WC2", "WC3", 
"RGU1", "ORS1", "WC1", "WC2", "WC3", "WC1", "WC2", "WC3", "WC1", 
"WC2", "WC3", "IC2", "IC1", "RGD1", "IC3", "IC2", "IC1", "IC3", 
"IC2")), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA, 
-500L))

我不确定这是否是您所说的发生率 table 但我们可以通过 dplyrtidyr 和 [=13 一次完成很多工作=]

x$count <- 1
x2 <- split(x, x$Species)
x2 <- lapply(x2, function(x){split(x,x$Week)})
x3 <- lapply(x2, function(x){lapply(X=x, function(y){
  y <- y %>% spread(key = "SiteVisits",
                    value = "count",
                    fill =0) %>%
    select(-Species, -Week) %>% as.data.frame()
  rownames(y) <- y$TagID
  y <- y[,-1]
  y <- graph_from_incidence_matrix(y)
  return(y)
})})

x3 将是一个列表结构,其中最终元素是 graph_from_incidence_matrix

的返回值