Я пытаюсь заполнить неявные пропущенные значения в кадре данных, который описывает процент покрытия трех различных категорий водорослей для всех трех сторон (N, S и T) для всех 12 модулей на двух площадках (WAI и HAN). Некоторые данные покрытия отсутствуют, так как «Метка» (T, MA, CCA) В частности, у меня возникли проблемы с заполнением неявных пропущенных значений для «CCA» в столбце «Метка» для сайта «WAI».
Я полагаю, что причина, по которой у меня возникла эта проблема, заключается в том, что "CCA" отсутствует для большинства сторон и модулей на сайте WAI. Однако я не уверен, как решить эту проблему.
Конечная цель для каждой комбинации «Дата», «Место», «Модуль» и «Сторона» - представить все три категории (T, MA, CCA). Если какая-либо из этих трех категорий отсутствует, я хочу, чтобы n = 0 и процент_крытия = 0. Таким образом, все неявно пропущенные значения становятся явными.
Как упоминалось ранее, я использовал полную функцию в dplyr для заполнения неявно пропущенных категорий "меток" (T, MA, CCA). Однако все комбинации Дата, Сайт, Модуль и Сторона не включают все три Метки, особенно для сайта WAI.
MA_cover_final <- structure(list(Date = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L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N", "S", "T"), class = "factor"), nn = c(50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 49L, 49L, 49L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 49L,
49L, 49L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 46L, 46L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 49L, 49L, 51L, 51L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 47L, 47L, 50L, 51L, 51L, 50L, 50L, 50L,
50L, 41L, 41L, 48L, 48L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 49L,
49L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 49L, 50L, 50L, 50L, 50L, 50L, 50L, 49L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
51L, 51L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 49L, 49L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 49L, 49L, 49L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L, 50L,
50L, 50L, 50L, 50L), Label = c("CCA", "MA", "T", "CCA", "MA",
"T", "CCA", "T", "MA", "T", "MA", "T", "MA", "T", "CCA",
"MA", "T", "CCA", "MA", "T", "MA", "T", "MA", "T", "CCA",
"MA", "T", "CCA", "T", "CCA", "MA", "T", "CCA", "T", "T",
"CCA", "MA", "T", "MA", "T", "T", "MA", "T", "CCA", "MA",
"T", "T", "MA", "T", "T", "MA", "T", "MA", "T", "T", "T",
"MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA",
"T", "MA", "T", "MA", "T", "MA", "T", "T", "T", "MA", "T",
"CCA", "MA", "T", "T", "CCA", "MA", "T", "MA", "T", "CCA",
"T", "T", "MA", "T", "MA", "T", "CCA", "MA", "T", "CCA",
"MA", "T", "T", "CCA", "T", "MA", "T", "T", "MA", "T", "MA",
"T", "T", "MA", "T", "MA", "T", "T", "MA", "T", "MA", "T",
"MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA",
"T", "MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA", "T",
"MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA",
"T", "MA", "T", "T", "MA", "T", "MA", "T", "MA", "T", "MA",
"T", "MA", "T", "T", "MA", "T", "MA", "T", "MA", "T", "MA",
"T", "T", "T", "MA", "T", "T", "T", "CCA", "MA", "T", "CCA",
"MA", "T", "CCA", "T", "MA", "T", "MA", "T", "T", "CCA",
"MA", "T", "CCA", "MA", "T", "T", "CCA", "MA", "T", "CCA",
"MA", "T", "T", "T", "MA", "T", "T", "MA", "T", "MA", "T",
"MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA", "T", "MA",
"T", "MA", "T", "T", "MA", "T", "MA", "T", "MA", "T", "MA",
"T", "MA", "T", "CCA", "MA", "T", "CCA", "MA", "T", "CCA",
"T", "MA", "T", "MA", "T", "MA", "T", "CCA", "MA", "T", "CCA",
"MA", "T", "T", "MA", "T", "MA", "T", "T", "CCA", "MA", "T",
"CCA", "MA", "T", "MA", "T", "MA", "T", "MA", "T", "T"),
n = c(1L, 5L, 34L, 3L, 2L, 39L, 1L, 6L, 5L, 37L, 4L, 38L,
3L, 9L, 1L, 3L, 26L, 2L, 6L, 28L, 1L, 9L, 3L, 29L, 1L, 6L,
34L, 1L, 7L, 3L, 1L, 28L, 1L, 16L, 5L, 1L, 6L, 39L, 5L, 37L,
4L, 1L, 48L, 1L, 2L, 42L, 39L, 3L, 43L, 45L, 1L, 37L, 3L,
39L, 38L, 47L, 5L, 34L, 2L, 40L, 6L, 40L, 6L, 42L, 3L, 46L,
1L, 45L, 4L, 40L, 3L, 42L, 3L, 39L, 46L, 48L, 3L, 31L, 1L,
1L, 36L, 10L, 2L, 1L, 43L, 1L, 42L, 1L, 1L, 36L, 1L, 33L,
1L, 9L, 1L, 1L, 45L, 3L, 5L, 36L, 6L, 1L, 41L, 1L, 40L, 7L,
3L, 43L, 3L, 41L, 34L, 4L, 45L, 2L, 44L, 29L, 8L, 39L, 6L,
40L, 2L, 34L, 8L, 31L, 2L, 40L, 1L, 35L, 3L, 46L, 5L, 42L,
1L, 41L, 2L, 43L, 3L, 44L, 1L, 35L, 3L, 44L, 7L, 43L, 1L,
48L, 7L, 38L, 2L, 40L, 3L, 40L, 6L, 37L, 9L, 38L, 44L, 1L,
39L, 4L, 27L, 4L, 44L, 5L, 42L, 9L, 38L, 48L, 5L, 36L, 8L,
33L, 3L, 38L, 1L, 47L, 50L, 12L, 2L, 31L, 33L, 30L, 1L, 3L,
40L, 3L, 1L, 38L, 1L, 21L, 3L, 32L, 1L, 29L, 29L, 2L, 3L,
38L, 2L, 3L, 36L, 15L, 1L, 1L, 35L, 1L, 3L, 35L, 24L, 44L,
2L, 46L, 42L, 4L, 42L, 3L, 44L, 3L, 24L, 2L, 45L, 3L, 40L,
3L, 46L, 2L, 42L, 6L, 42L, 1L, 41L, 46L, 5L, 41L, 1L, 42L,
5L, 41L, 4L, 36L, 3L, 31L, 2L, 5L, 34L, 4L, 4L, 23L, 1L,
3L, 13L, 28L, 7L, 40L, 4L, 28L, 1L, 1L, 43L, 3L, 2L, 41L,
16L, 4L, 34L, 3L, 31L, 5L, 1L, 4L, 25L, 4L, 4L, 28L, 1L,
3L, 2L, 46L, 3L, 41L, 4L), percent_cover = c(0.02, 0.1, 0.68,
0.06, 0.04, 0.78, 0.02, 0.12, 0.1, 0.74, 0.08, 0.76, 0.06,
0.18, 0.0204081632653061, 0.0612244897959184, 0.530612244897959,
0.04, 0.12, 0.56, 0.02, 0.18, 0.06, 0.58, 0.0204081632653061,
0.122448979591837, 0.693877551020408, 0.02, 0.14, 0.06, 0.02,
0.56, 0.02, 0.32, 0.1, 0.02, 0.12, 0.78, 0.1, 0.74, 0.08,
0.02, 0.96, 0.02, 0.04, 0.84, 0.78, 0.06, 0.86, 0.9, 0.0217391304347826,
0.804347826086957, 0.06, 0.78, 0.76, 0.94, 0.1, 0.68, 0.04,
0.8, 0.12, 0.8, 0.12, 0.84, 0.06, 0.92, 0.02, 0.9, 0.0816326530612245,
0.816326530612245, 0.0588235294117647, 0.823529411764706,
0.06, 0.78, 0.92, 0.96, 0.06, 0.62, 0.02, 0.02, 0.72, 0.2,
0.04, 0.02, 0.86, 0.02, 0.84, 0.02, 0.02, 0.72, 0.02, 0.66,
0.02, 0.18, 0.02, 0.02, 0.9, 0.06, 0.1, 0.72, 0.12, 0.02,
0.82, 0.02, 0.8, 0.14, 0.06, 0.86, 0.06, 0.82, 0.68, 0.08,
0.9, 0.0425531914893617, 0.936170212765957, 0.58, 0.156862745098039,
0.764705882352941, 0.12, 0.8, 0.04, 0.68, 0.195121951219512,
0.75609756097561, 0.0416666666666667, 0.833333333333333,
0.02, 0.7, 0.06, 0.92, 0.1, 0.84, 0.02, 0.82, 0.04, 0.86,
0.06, 0.88, 0.02, 0.7, 0.06, 0.88, 0.14, 0.86, 0.0204081632653061,
0.979591836734694, 0.14, 0.76, 0.04, 0.8, 0.06, 0.8, 0.12,
0.74, 0.18, 0.76, 0.88, 0.02, 0.78, 0.08, 0.54, 0.08, 0.88,
0.1, 0.84, 0.18, 0.76, 0.96, 0.1, 0.72, 0.16, 0.66, 0.06,
0.76, 0.02, 0.94, 1, 0.24, 0.04, 0.62, 0.66, 0.6, 0.02, 0.06,
0.8, 0.06, 0.02, 0.76, 0.02, 0.42, 0.06, 0.64, 0.02, 0.58,
0.591836734693878, 0.04, 0.06, 0.76, 0.04, 0.06, 0.72, 0.306122448979592,
0.02, 0.02, 0.7, 0.02, 0.06, 0.7, 0.48, 0.88, 0.04, 0.92,
0.84, 0.08, 0.84, 0.06, 0.88, 0.0588235294117647, 0.470588235294118,
0.04, 0.9, 0.06, 0.8, 0.06, 0.92, 0.04, 0.84, 0.12, 0.84,
0.02, 0.82, 0.92, 0.1, 0.82, 0.02, 0.84, 0.102040816326531,
0.836734693877551, 0.08, 0.72, 0.06, 0.62, 0.04, 0.1, 0.68,
0.08, 0.08, 0.46, 0.02, 0.06, 0.26, 0.56, 0.14, 0.8, 0.08,
0.56, 0.0204081632653061, 0.0204081632653061, 0.877551020408163,
0.06, 0.04, 0.82, 0.32, 0.08, 0.68, 0.06, 0.62, 0.1, 0.02,
0.08, 0.5, 0.08, 0.08, 0.56, 0.02, 0.06, 0.04, 0.92, 0.06,
0.82, 0.08)), class = c("tbl_df", "tbl", "data.frame"), row.names = c(NA,
-281L))
MA_cover_final <- MA_cover_final %>% group_by(Date, Site) %>%
complete(Side, Label, fill = list(n = 0, percent_cover = 0)) %>%
ungroup()
Результирующий кадр данных должен иметь 432 строки [12 модулей (1-12) x 3 стороны (N, S, T) x 3 метки («T», «MA», «CCA») x 4 даты]