【发布时间】:2014-11-30 19:35:59
【问题描述】:
我一直在环顾四周,但仍然找不到按时间对数据帧进行子集化的方法,这是示例数据:
Duration End Date Start Date
228 2013-01-03 09:10:00 2013-01-03 09:06:00
1675 2013-01-04 17:34:00 2013-01-04 17:06:00
393 2013-01-04 17:54:00 2013-01-04 17:48:00
426 2013-01-04 11:10:00 2013-01-04 11:03:00
827 2013-01-01 16:13:00 2013-01-01 15:59:00
780 2013-01-01 16:13:00 2013-01-01 16:00:00
结束日期和开始日期采用 POSIXct 格式,如果我只是在 8:00 到 9:30 之间的时间,这是我尝试过的。
tm1 <- as.POSIXct("08:00", format = "%H:%M")
tm2 <- as.POSIXct("09:30", format = "%H:%M")
df.time <- with(df, df[format('Start Date', '%H:%M')>= tm1 & format('End Date', '%H:%M')< tm2, ])
但这会返回错误。我也试过这个,但效果不佳。
df.time <- subset(df, format('Start Date', '%H:%M') >= '8:00' & format('End Date', '%H:%M') < '9:30'))
如果有人告诉我我做错了什么?谢谢
【问题讨论】: