Я выполняю базовую c агрегацию 30-летних наблюдений за отдельными животными, и у меня есть файл сырых данных, где есть одна строка для каждого отдельного наблюдения за животным, где индивидуальное имя и время наблюдения являются параметрами.
Этот скрипт дает длинный формат таблицы, и мне нужен длинный формат:
table(dis2$who, lubridate::year(dis2$tid))
Вот данные:
> dput(dis2)
structure(list(who = c("KA-3", "KA-4", "KA-4", "KA-5", "KA-6",
"KA-6", "KA-7", "KA-7", "KA-8", "KA-8", "KA-12", "KA-12", "KA-12",
"KB-4", "KB-4", "KB-4", "KB-4", "KB-4", "KB-4", "KB-4", "KB-6",
"KB-6", "KB-6", "KB-6", "KB-6", "KB-6", "KB-6", "KB-6", "KB-6",
"KB-6", "KB-6", "KB-6", "KB-6", "KB-6", "KB-7", "KB-7", "KB-7",
"KB-7", "KB-11", "KB-11", "KB-11", "KB-11", "KB-11", "KB-11",
"KB-11", "KB-11", "KB-11", "KB-11", "KB-11", "KB-11", "KC-1",
"KC-1", "KC-1", "KC-3", "KC-3", "KE-1", "KE-1", "KE-1", "KE-1",
"KE-1", "KE-1", "KE-3", "KF-1", "KF-1", "KF-1", "KF-1", "KF-1",
"KG-6", "KG-6", "KG-6", "KH-2", "KH-2", "KH-2", "KH-3", "KH-3",
"KH-4", "KH-4", "KH-5", "KH-5", "KH-6", "KH-6", "KH-7", "KH-7",
"KH-7", "KI-1", "KI-1", "KI-1", "KI-1", "KI-1", "KI-1", "KI-1",
"KI-1", "KI-1", "KI-1", "KI-1", "KI-1", "KI-1", "KI-1", "KI-1"
), film = c(14, 10, 14, 18, 10, 18, 14, 14, 10, 14, 15, 18, 19,
20, 30, 37, 47, 48, 48, 49, 23, 23, 30, 32, 35, 38, 41, 43, 47,
48, 48, 48, 49, 49, 36, 37, 43, 49, 36, 36, 36, 36, 37, 38, 39,
42, 43, 47, 48, 49, 50, 51, 998, 50, 50, 73, 73, 73, 74, 74,
74, 74, 8, 8, 8, 8, 52, 88, 90, 91, 84, 84, 92, 92, 93, 92, 104,
92, 93, 84, 93, 93, 93, 94, 999, 999, 95, 95, 96, 96, 97, 97,
97, 98, 98, 98, 99, 99, 102), frame = c(36, 15, 34, 16, 18, 15,
35, 37, 13, 35, 27, 18, 14, 17, 24, 17, 11, 22, 24, 34, 29, 31,
25, 15, 18, 12, 5, 23, 19, 9, 10, 14, 16, 17, 37, 15, 8, 14,
29, 33, 35, 37, 18, 22, 22, 33, 10, 8, 21, 36, 30, 8, 1, 2, 3,
2, 19, 36, 3, 5, 21, 8, 4, 8, 11, 14, 2, 19, 16, 16, 24, 26,
6, 21, 19, 27, 8, 30, 26, 25, 30, 20, 33, 19, 1, 2, 1, 24, 19,
22, 15, 17, 19, 5, 9, 27, 1, 8, 1), tid = structure(c(570067200,
570067200, 570067200, 570412800, 570067200, 570412800, 570067200,
570067200, 570067200, 570067200, 570067200, 570412800, 570412800,
633744000, 634435200, 634608000, 635126400, 635126400, 635126400,
635126400, 633744000, 633744000, 634435200, 634435200, 634521600,
634694400, 635040000, 635040000, 635126400, 635126400, 635126400,
635126400, 635126400, 635126400, 634608000, 634608000, 635040000,
635126400, 634608000, 634608000, 634608000, 634608000, 634608000,
634694400, 635040000, 635040000, 635040000, 635126400, 635126400,
635126400, 640483200, 640483200, 640483200, 640483200, 640483200,
659664000, 659664000, 659664000, 659664000, 659664000, 659664000,
659664000, 569721600, 569721600, 569721600, 569721600, 656035200,
668476800, 668476800, 668476800, 668476800, 668476800, 668476800,
668476800, 668476800, 668476800, 668736000, 668476800, 668476800,
668476800, 668476800, 668476800, 668476800, 668476800, 575424000,
655948800, 668563200, 668563200, 668563200, 668563200, 668563200,
668563200, 668563200, 668563200, 668563200, 668563200, 668563200,
668563200, 668649600), class = c("POSIXct", "POSIXt"), tzone = "UTC")),
class = "data.frame", row.names = c(NA,-99L))