【发布时间】:2018-05-11 10:31:52
【问题描述】:
我刚开始使用 R,所以请多多包涵
例如,我有这个data.table(或data.frame)对象:
Time Station count_starts count_ends
01/01/2015 00:30 A 2 3
01/01/2015 00:40 A 2 1
01/01/2015 00:55 B 1 1
01/01/2015 01:17 A 3 1
01/01/2015 01:37 A 1 1
我的最终目标是将“时间”列分组为每小时,并根据每小时的时间和站点对count_starts 和count_ends 求和:
Time Station sum(count_starts) sum(count_ends)
01/01/2015 01:00 A 4 4
01/01/2015 01:00 B 1 1
01/01/2015 02:00 A 4 2
我做了一些研究,发现我应该使用xts 库。
谢谢你帮助我
更新:
我将transactions$Time的类型转换为POSIXct,所以xts包应该可以直接使用timeseries了。
【问题讨论】:
-
感谢您的链接,我可以按小时“分组”日期时间,但困难的部分是如何按小时费率对其他列求和?
标签: r dataframe time-series