R中每小时按时间戳数据计算的平均班级数量

时间:2019-04-05 13:39:58

标签: r

我正在学习R,所以我寻求帮助以举一个示例,说明如何编写以下转换。

以下是我正在使用的数据的示例:

> head(clas1)
   GMT_DATE GMT_TIME    clas1
1: 6/1/2016 00:04:00 Foraging
2: 6/1/2016 00:08:00 Foraging
3: 6/1/2016 00:12:00 Foraging
4: 6/1/2016 00:16:00 Foraging
5: 6/1/2016 00:20:00 Foraging
6: 6/1/2016 00:24:00 Foraging

此数据每隔四分钟(GMT_TIME)有几天(GMT_DATE)的时间戳。每个时间戳在三个不同的类clas1ForagingFeeding中都有一个关联的Standing事件。

我想要的输出是一个数据帧,该数据帧将平均每天(从023的每个班级的小时计数。这是一个没有值的示例,其中包括sd

Time_day avg_Standing sd_Standing avg_Feeding _sd_Feeding avg_Foraging sd_Foraging
0
1
2
3
4
5 

困难的事实是我有一个字符串而不是值。我希望有人至少可以使我走上正确的道路。任何帮助表示赞赏!

PS:请在下面找到一个dput()示例:

> dput(clas1[c(1:600),])
structure(list(GMT_DATE = c("6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", "6/1/2016", 
"6/1/2016", "6/1/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", "6/2/2016", 
"6/2/2016", "6/2/2016", "6/2/2016"), GMT_TIME = c("00:04:00", 
"00:08:00", "00:12:00", "00:16:00", "00:20:00", "00:24:00", "00:28:00", 
"00:32:00", "00:36:00", "00:40:00", "00:44:00", "00:48:00", "00:52:00", 
"00:56:00", "01:00:00", "01:04:00", "01:08:00", "01:12:00", "01:16:00", 
"01:20:00", "01:24:00", "01:28:00", "01:32:00", "01:36:00", "01:40:00", 
"01:44:00", "01:48:00", "01:52:00", "01:56:00", "02:00:00", "02:04:00", 
"02:08:00", "02:12:00", "02:16:00", "02:20:00", "02:24:00", "02:28:00", 
"02:32:00", "02:36:00", "02:40:00", "02:44:00", "02:48:00", "02:52:00", 
"02:56:00", "03:00:00", "03:04:00", "03:08:00", "03:12:00", "03:16:00", 
"03:20:00", "03:24:00", "03:28:00", "03:32:00", "03:36:00", "03:40:00", 
"03:44:00", "03:48:00", "03:52:00", "03:56:00", "04:00:00", "04:04:00", 
"04:08:00", "04:12:00", "04:16:00", "04:20:00", "04:24:00", "04:28:00", 
"04:32:00", "04:36:00", "04:40:00", "04:44:00", "04:48:00", "04:52:00", 
"04:56:00", "05:00:00", "05:04:00", "05:08:00", "05:12:00", "05:16:00", 
"05:20:00", "05:24:00", "05:28:00", "05:32:00", "05:36:00", "05:40:00", 
"05:44:00", "05:48:00", "05:52:00", "05:56:00", "06:00:00", "06:04:00", 
"06:08:00", "06:12:00", "06:16:00", "06:20:00", "06:24:00", "06:28:00", 
"06:32:00", "06:36:00", "06:40:00", "06:44:00", "06:48:00", "06:52:00", 
"06:56:00", "07:00:00", "07:04:00", "07:08:00", "07:12:00", "07:16:00", 
"07:20:00", "07:24:00", "07:28:00", "07:32:00", "07:36:00", "07:40:00", 
"07:44:00", "07:48:00", "07:52:00", "07:56:00", "08:00:00", "08:04:00", 
"08:08:00", "08:12:00", "08:16:00", "08:20:00", "08:24:00", "08:28:00", 
"08:32:00", "08:36:00", "08:40:00", "08:44:00", "08:48:00", "08:52:00", 
"08:56:00", "09:00:00", "09:04:00", "09:08:00", "09:12:00", "09:16:00", 
"09:20:00", "09:24:00", "09:28:00", "09:32:00", "09:36:00", "09:40:00", 
"09:44:00", "09:48:00", "09:52:00", "09:56:00", "10:00:00", "10:04:00", 
"10:08:00", "10:12:00", "10:16:00", "10:20:00", "10:24:00", "10:28:00", 
"10:32:00", "10:36:00", "10:40:00", "10:44:00", "10:48:00", "10:52:00", 
"10:56:00", "11:00:00", "11:04:00", "11:08:00", "11:12:00", "11:16:00", 
"11:20:00", "11:24:00", "11:28:00", "11:32:00", "11:36:00", "11:40:00", 
"11:44:00", "11:48:00", "11:52:00", "11:56:00", "12:00:00", "12:04:00", 
"12:08:00", "12:12:00", "12:16:00", "12:20:00", "12:24:00", "12:28:00", 
"12:32:00", "12:36:00", "12:40:00", "12:44:00", "12:48:00", "12:52:00", 
"12:56:00", "13:00:00", "13:04:00", "13:08:00", "13:12:00", "13:16:00", 
"13:20:00", "13:24:00", "13:28:00", "13:32:00", "13:36:00", "13:40:00", 
"13:44:00", "13:48:00", "13:52:00", "13:56:00", "14:00:00", "14:04:00", 
"14:08:00", "14:12:00", "14:16:00", "14:20:00", "14:24:00", "14:28:00", 
"14:32:00", "14:36:00", "14:40:00", "14:44:00", "14:48:00", "14:52:00", 
"14:56:00", "15:00:00", "15:04:00", "15:08:00", "15:12:00", "15:16:00", 
"15:20:00", "15:24:00", "15:28:00", "15:32:00", "15:36:00", "15:40:00", 
"15:44:00", "15:48:00", "15:52:00", "15:56:00", "16:00:00", "16:04:00", 
"16:08:00", "16:12:00", "16:16:00", "16:20:00", "16:24:00", "16:28:00", 
"16:32:00", "16:36:00", "16:40:00", "16:44:00", "16:48:00", "16:52:00", 
"16:56:00", "17:00:00", "17:04:00", "17:08:00", "17:12:00", "17:16:00", 
"17:20:00", "17:24:00", "17:28:00", "17:32:00", "17:36:00", "17:40:00", 
"17:44:00", "17:48:00", "17:52:00", "17:56:00", "18:00:00", "18:04:00", 
"18:08:00", "18:12:00", "18:16:00", "18:20:00", "18:24:00", "18:28:00", 
"18:32:00", "18:36:00", "18:40:00", "18:44:00", "18:48:00", "18:52:00", 
"18:56:00", "19:00:00", "19:04:00", "19:08:00", "19:12:00", "19:16:00", 
"19:20:00", "19:24:00", "19:28:00", "19:32:00", "19:36:00", "19:40:00", 
"19:44:00", "19:48:00", "19:52:00", "19:56:00", "20:00:00", "20:04:00", 
"20:08:00", "20:12:00", "20:16:00", "20:20:00", "20:24:00", "20:28:00", 
"20:32:00", "20:36:00", "20:40:00", "20:44:00", "20:48:00", "20:52:00", 
"20:56:00", "21:00:00", "21:04:00", "21:08:00", "21:12:00", "21:16:00", 
"21:20:00", "21:24:00", "21:28:00", "21:32:00", "21:36:00", "21:40:00", 
"21:44:00", "21:48:00", "21:52:00", "21:56:00", "22:00:00", "22:04:00", 
"22:08:00", "22:12:00", "22:16:00", "22:20:00", "22:24:00", "22:28:00", 
"22:32:00", "22:36:00", "22:40:00", "22:44:00", "22:48:00", "22:52:00", 
"22:56:00", "23:00:00", "23:04:00", "23:08:00", "23:12:00", "23:16:00", 
"23:20:00", "23:24:00", "23:28:00", "23:32:00", "23:36:00", "23:40:00", 
"23:44:00", "23:48:00", "23:52:00", "23:56:00", "00:00:00", "00:04:00", 
"00:08:00", "00:12:00", "00:16:00", "00:20:00", "00:24:00", "00:28:00", 
"00:32:00", "00:36:00", "00:40:00", "00:44:00", "00:48:00", "00:52:00", 
"00:56:00", "01:00:00", "01:04:00", "01:08:00", "01:12:00", "01:16:00", 
"01:20:00", "01:24:00", "01:28:00", "01:32:00", "01:36:00", "01:40:00", 
"01:44:00", "01:48:00", "01:52:00", "01:56:00", "02:00:00", "02:04:00", 
"02:08:00", "02:12:00", "02:16:00", "02:20:00", "02:24:00", "02:28:00", 
"02:32:00", "02:36:00", "02:40:00", "02:44:00", "02:48:00", "02:52:00", 
"02:56:00", "03:00:00", "03:04:00", "03:08:00", "03:12:00", "03:16:00", 
"03:20:00", "03:24:00", "03:28:00", "03:32:00", "03:36:00", "03:40:00", 
"03:44:00", "03:48:00", "03:52:00", "03:56:00", "04:00:00", "04:04:00", 
"04:08:00", "04:12:00", "04:16:00", "04:20:00", "04:24:00", "04:28:00", 
"04:32:00", "04:36:00", "04:40:00", "04:44:00", "04:48:00", "04:52:00", 
"04:56:00", "05:00:00", "05:04:00", "05:08:00", "05:12:00", "05:16:00", 
"05:20:00", "05:24:00", "05:28:00", "05:32:00", "05:36:00", "05:40:00", 
"05:44:00", "05:48:00", "05:52:00", "05:56:00", "06:00:00", "06:04:00", 
"06:08:00", "06:12:00", "06:16:00", "06:20:00", "06:24:00", "06:28:00", 
"06:32:00", "06:36:00", "06:40:00", "06:44:00", "06:48:00", "06:52:00", 
"06:56:00", "07:00:00", "07:04:00", "07:08:00", "07:12:00", "07:16:00", 
"07:20:00", "07:24:00", "07:28:00", "07:32:00", "07:36:00", "07:40:00", 
"07:44:00", "07:48:00", "07:52:00", "07:56:00", "08:00:00", "08:04:00", 
"08:08:00", "08:12:00", "08:16:00", "08:20:00", "08:24:00", "08:28:00", 
"08:32:00", "08:36:00", "08:40:00", "08:44:00", "08:48:00", "08:52:00", 
"08:56:00", "09:00:00", "09:04:00", "09:08:00", "09:12:00", "09:16:00", 
"09:20:00", "09:24:00", "09:28:00", "09:32:00", "09:36:00", "09:40:00", 
"09:44:00", "09:48:00", "09:52:00", "09:56:00", "10:00:00", "10:04:00", 
"10:08:00", "10:12:00", "10:16:00", "10:20:00", "10:24:00", "10:28:00", 
"10:32:00", "10:36:00", "10:40:00", "10:44:00", "10:48:00", "10:52:00", 
"10:56:00", "11:00:00", "11:04:00", "11:08:00", "11:12:00", "11:16:00", 
"11:20:00", "11:24:00", "11:28:00", "11:32:00", "11:36:00", "11:40:00", 
"11:44:00", "11:48:00", "11:52:00", "11:56:00", "12:00:00", "12:04:00", 
"12:08:00", "12:12:00", "12:16:00", "12:20:00", "12:24:00", "12:28:00", 
"12:32:00", "12:36:00", "12:40:00", "12:44:00", "12:48:00", "12:52:00", 
"12:56:00", "13:00:00", "13:04:00", "13:08:00", "13:12:00", "13:16:00", 
"13:20:00", "13:24:00", "13:28:00", "13:32:00", "13:36:00", "13:40:00", 
"13:44:00", "13:48:00", "13:52:00", "13:56:00", "14:00:00", "14:04:00", 
"14:08:00", "14:12:00", "14:16:00", "14:20:00", "14:24:00", "14:28:00", 
"14:32:00", "14:36:00", "14:40:00", "14:44:00", "14:48:00", "14:52:00", 
"14:56:00", "15:00:00", "15:04:00", "15:08:00", "15:12:00", "15:16:00", 
"15:20:00", "15:24:00", "15:28:00", "15:32:00", "15:36:00", "15:40:00", 
"15:44:00", "15:48:00", "15:52:00", "15:56:00", "16:00:00"), 
    clas1 = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 1L, 3L, 3L, 3L, 3L, 3L, 1L, 
    1L, 1L, 3L, 3L, 3L, 1L, 1L, 1L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 
    3L, 1L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 1L, 1L, 1L, 3L, 
    1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 1L, 1L, 1L, 3L, 1L,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L, 1L, 
    1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 2L, 2L, 2L, 3L, 3L, 
    3L, 3L, 3L, 3L, 3L), .Label = c("Feeding", "Foraging", "Standing"
    ), class = "factor")), row.names = c(NA, -600L), class = c("data.table", 
"data.frame"), .internal.selfref = <pointer: 0x00000000026c1ef0>)

1 个答案:

答案 0 :(得分:0)

使用ggplottidyverse,您可以先汇总数据,然后绘制数据:

library(ggplot2)
library(tidyverse)

(agg_df <- df %>% 
  as_tibble() %>%
  mutate(tms  = as.POSIXct(paste0(GMT_DATE, "-", GMT_TIME), format = "%m/%d/%Y-%H:%M:%S"),
         hour = hour(tms),
         day  = day(tms)) %>% ## create aux columns with day and hour
  group_by(day, hour) %>%
  summarise(tab = list(as.data.frame(table(clas1)))) %>%
  unnest() %>%
  group_by(hour, clas1) %>%
  summarise(stats = list(mean_cl_normal(Freq))) %>%
  unnest())

# # A tibble: 72 x 5
# # Groups:   hour [24]
#     hour clas1        y   ymin  ymax
#    <int> <fct>    <dbl>  <dbl> <dbl>
#  1     0 Feeding    0     0     0   
#  2     0 Foraging  14.5   8.15 20.9 
#  3     0 Standing   0     0     0   
#  4     1 Feeding    6.5 -25.3  38.3 
#  5     1 Foraging   2   -10.7  14.7 
#  6     1 Standing   6.5 -12.6  25.6 
#  7     2 Feeding    4.5  -1.85 10.9 
#  8     2 Foraging   9     9     9   
#  9     2 Standing   1.5  -4.85  7.85
# 10     3 Feeding   11   -14.4  36.4 
# # ... with 62 more rows

agg_df现在包含所有必要的列:

  • y:每小时clas1的平均计数(按天平均)
  • ymin, ymax:假设正常法则,平均计数的上下置信区间

此数据框现在可用于绘制:

ggplot(agg_df, aes(x = hour, y = y, fill = clas1, ymin = ymin, ymax = ymax)) +
    geom_col(position = position_dodge2()) +
    geom_errorbar(position = position_dodge2())

注意

使用正常定律来获得计数的置信度并不是最好的主意,但是如果您有大量的平均天数(至少50天左右),则可以证明是合理的。基于泊松的方法将更为准确。

Barchart with errorbars