筛选R中某个时间范围之间的所有天数 [英] Filter all days between a time range in R
本文介绍了筛选R中某个时间范围之间的所有天数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个如下数据框:
entry_no id time
_________ ___ _____
1 1 2016-09-01 09:30:09
2 2 2016-09-02 10:36:18
3 1 2016-09-01 12:27:27
4 3 2016-09-03 10:24:30
5 1 2016-09-01 12:35:39
6 3 2016-09-06 10:19:45
我想每天过滤从上午9点到上午10点之间发生的条目。我知道有一天可以使用
From this I want to filter the entries which occurs between the time 9 am to 10 am for every day.I know for one day I can use something like:
results=filter(df,time>='2016-09-01 09:00:00' && time<='2016-09-01 10:00:00')
但要过滤
推荐答案
您可以通过一些简单的格式来实现它:
You could achieve it with a bit of simple formatting:
dat$hms <- format(as.POSIXct(dat$time), "%H:%M:%S")
dat[dat$hms >= "09:00:00" & dat$hms <= "10:00:00",]
# entry_no id time hms
#1 1 1 2016-09-01 09:30:09 09:30:09
这篇关于筛选R中某个时间范围之间的所有天数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文