lubridate
在这里很有用。没有它,您需要编写自己的重叠检查,这有点痛苦......
library(lubridate)
badRange <- as.interval(days(1), as.POSIXct("2012/1/3"))
> mainTimeSeries %within% badRange
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[22] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[43] FALSE FALSE FALSE FALSE FALSE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE
[64] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
[85] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE
>
或者:
> mainTimeSeries[mainTimeSeries %within% badRange]
[1] "2012-01-03 00:00:00 PST" "2012-01-03 01:00:00 PST" "2012-01-03 02:00:00 PST" "2012-01-03 03:00:00 PST"
[5] "2012-01-03 04:00:00 PST" "2012-01-03 05:00:00 PST" "2012-01-03 06:00:00 PST" "2012-01-03 07:00:00 PST"
[9] "2012-01-03 08:00:00 PST" "2012-01-03 09:00:00 PST" "2012-01-03 10:00:00 PST" "2012-01-03 11:00:00 PST"
[13] "2012-01-03 12:00:00 PST" "2012-01-03 13:00:00 PST" "2012-01-03 14:00:00 PST" "2012-01-03 15:00:00 PST"
[17] "2012-01-03 16:00:00 PST" "2012-01-03 17:00:00 PST" "2012-01-03 18:00:00 PST" "2012-01-03 19:00:00 PST"
[21] "2012-01-03 20:00:00 PST" "2012-01-03 21:00:00 PST" "2012-01-03 22:00:00 PST" "2012-01-03 23:00:00 PST"
[25] "2012-01-04 00:00:00 PST"
>
仅使用基础 R:
bad_start <- as.POSIXct('2012/1/3')
bad_end <- as.POSIXct('2012/1/4')
mainTimeSeries[mainTimeSeries > bad_end | mainTimeSeries < bad_start]