通过从日期时间中过滤 4 小时间隔来创建数据集
我希望创建一个数据集,其中仅包含相隔 4 小时的每次观察的数据。 目前我拥有一个每小时观察的数据集。 划分不起作用,因为样本之间没有 4 小时的间隔。
IndividId DateTimeLMT isDaylight YEAR month day hour
<chr> <dttm> <chr> <dbl> <dbl> <dbl> <dbl>
1 M_15_03 2017-01-13 15:00:42 True 2017 1 13 15
2 M_15_03 2017-01-13 16:00:14 False 2017 1 13 16
3 M_15_03 2017-01-13 17:00:09 False 2017 1 13 17
4 M_15_03 2017-01-13 18:00:42 False 2017 1 13 18
5 M_15_03 2017-01-13 19:00:14 False 2017 1 13 19
6 M_15_03 2017-01-13 20:00:45 False 2017 1 13 20
我想要的结果是一个可以创建与此类似的公式:
IndividId DateTimeLMT isDaylight YEAR month day hour
<chr> <dttm> <chr> <dbl> <dbl> <dbl> <dbl>
1 M_15_03 2017-01-13 15:00:42 True 2017 1 13 15
2 M_15_03 2017-01-13 19:00:14 False 2017 1 13 19
3 M_15_03 2017-01-13 23:00:09 False 2017 1 13 23
4 M_15_03 2017-01-14 03:00:42 False 2017 1 14 03
5 M_15_03 2017-01-14 07:00:14 False 2017 1 14 07
6 M_15_03 2017-01-14 11:00:45 True 2017 1 14 11
I wish to create a dataset that only has the data from every observation 4 hours apart.
Currently I possess a dataset that has hourly observations.
Dividing does not work because the samples would not have 4 hour intervals between them.
IndividId DateTimeLMT isDaylight YEAR month day hour
<chr> <dttm> <chr> <dbl> <dbl> <dbl> <dbl>
1 M_15_03 2017-01-13 15:00:42 True 2017 1 13 15
2 M_15_03 2017-01-13 16:00:14 False 2017 1 13 16
3 M_15_03 2017-01-13 17:00:09 False 2017 1 13 17
4 M_15_03 2017-01-13 18:00:42 False 2017 1 13 18
5 M_15_03 2017-01-13 19:00:14 False 2017 1 13 19
6 M_15_03 2017-01-13 20:00:45 False 2017 1 13 20
The result I would be looking for is a formula that would create something similar to this:
IndividId DateTimeLMT isDaylight YEAR month day hour
<chr> <dttm> <chr> <dbl> <dbl> <dbl> <dbl>
1 M_15_03 2017-01-13 15:00:42 True 2017 1 13 15
2 M_15_03 2017-01-13 19:00:14 False 2017 1 13 19
3 M_15_03 2017-01-13 23:00:09 False 2017 1 13 23
4 M_15_03 2017-01-14 03:00:42 False 2017 1 14 03
5 M_15_03 2017-01-14 07:00:14 False 2017 1 14 07
6 M_15_03 2017-01-14 11:00:45 True 2017 1 14 11
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
lubridate::floor_date
。floor_date
设置为4 小时
将在 16 - 20 - 24 小时内四舍五入,因此您可以使用 Lead 来设置 15 - 19,并填充tidyr::填充
。数据
You can use
lubridate::floor_date
.floor_date
set to4 hours
will round at 16 - 20 - 24 hours, so you can use lead to make to 15 - 19, and fill withtidyr::fill
.data