假设我有一个包含开始和结束时间列、一个测量列和一个测量时间列的数据框,如下所示:
start end value time
9:01:00 9:02:00 30.6 2013-03-25 9:05:00
9:01:00 9:02:00 30.8 2013-03-25 9:15:00
9:46:00 9:46:00 28.2 2013-03-25 9:43:00
9:46:00 9:46:00 28.9 2013-03-25 9:53:00
10:54:00 10:59:00 13.4 2013-03-25 10:56:00
10:54:00 10:59:00 13.8 2013-03-25 11:56:00
如何将此数据框子集化为仅包含时间列在开始和结束时间或开始时间前十分钟和结束时间后十分钟内的行。我任意选择十分钟,并且想知道如何在开始和结束时间之前和之后的任何时间内执行此操作。
生成的数据框如下:
start end value time
9:01:00 9:02:00 30.6 2013-03-25 9:05:00
9:46:00 9:46:00 28.2 2013-03-25 9:43:00
9:46:00 9:46:00 28.9 2013-03-25 9:53:00
10:54:00 10:59:00 13.4 2013-03-25 10:56:00
除了从开始/结束列条目中减去/添加 x 分钟数,然后根据时间列是否位于这些扩展窗口之间进行子集之外,还有其他方法吗?
目前,我已将时间列转换为 POSIXlt 格式。不幸的是,这在开始和结束列中给出了今天的日期。
这是第一个数据帧的 dput:
structure(list(start = structure(list(sec = c(0, 0, 0, 0, 0,
0), min = c(1L, 1L, 46L, 46L, 54L, 54L), hour = c(9L, 9L, 9L,
9L, 10L, 10L), mday = c(7L, 7L, 7L, 7L, 7L, 7L), mon = c(7L,
7L, 7L, 7L, 7L, 7L), year = c(113L, 113L, 113L, 113L, 113L, 113L
), wday = c(3L, 3L, 3L, 3L, 3L, 3L), yday = c(218L, 218L, 218L,
218L, 218L, 218L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt")), end = structure(list(sec = c(0,
0, 0, 0, 0, 0), min = c(2L, 2L, 46L, 46L, 59L, 59L), hour = c(9L,
9L, 9L, 9L, 10L, 10L), mday = c(7L, 7L, 7L, 7L, 7L, 7L), mon = c(7L,
7L, 7L, 7L, 7L, 7L), year = c(113L, 113L, 113L, 113L, 113L, 113L
), wday = c(3L, 3L, 3L, 3L, 3L, 3L), yday = c(218L, 218L, 218L,
218L, 218L, 218L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt")), value = c(30.6, 30.8, 28.2,
28.9, 13.4, 13.8), time = structure(list(sec = c(0, 0, 0, 0,
0, 0), min = c(5L, 15L, 43L, 53L, 56L, 56L), hour = c(9L, 9L,
9L, 9L, 10L, 11L), mday = c(25L, 25L, 25L, 25L, 25L, 25L), mon = c(2L,
2L, 2L, 2L, 2L, 2L), year = c(113L, 113L, 113L, 113L, 113L, 113L
), wday = c(1L, 1L, 1L, 1L, 1L, 1L), yday = c(83L, 83L, 83L,
83L, 83L, 83L), isdst = c(1L, 1L, 1L, 1L, 1L, 1L)), .Names = c("sec",
"min", "hour", "mday", "mon", "year", "wday", "yday", "isdst"
), class = c("POSIXlt", "POSIXt"))), .Names = c("start", "end",
"value", "time"), row.names = c(NA, -6L), class = "data.frame")
这是第二个数据帧的输入
structure(list(start = structure(list(sec = c(0, 0, 0, 0), min = c(1L,
46L, 46L, 54L), hour = c(9L, 9L, 9L, 10L), mday = c(7L, 7L, 7L,
7L), mon = c(7L, 7L, 7L, 7L), year = c(113L, 113L, 113L, 113L
), wday = c(3L, 3L, 3L, 3L), yday = c(218L, 218L, 218L, 218L),
isdst = c(1L, 1L, 1L, 1L)), .Names = c("sec", "min", "hour",
"mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt",
"POSIXt")), end = structure(list(sec = c(0, 0, 0, 0), min = c(2L,
46L, 46L, 59L), hour = c(9L, 9L, 9L, 10L), mday = c(7L, 7L, 7L,
7L), mon = c(7L, 7L, 7L, 7L), year = c(113L, 113L, 113L, 113L
), wday = c(3L, 3L, 3L, 3L), yday = c(218L, 218L, 218L, 218L),
isdst = c(1L, 1L, 1L, 1L)), .Names = c("sec", "min", "hour",
"mday", "mon", "year", "wday", "yday", "isdst"), class = c("POSIXlt",
"POSIXt")), value = c(30.6, 28.2, 28.9, 13.4), time = structure(list(
sec = c(0, 0, 0, 0), min = c(5L, 43L, 53L, 56L), hour = c(9L,
9L, 9L, 10L), mday = c(25L, 25L, 25L, 25L), mon = c(2L, 2L,
2L, 2L), year = c(113L, 113L, 113L, 113L), wday = c(1L, 1L,
1L, 1L), yday = c(83L, 83L, 83L, 83L), isdst = c(1L, 1L,
1L, 1L)), .Names = c("sec", "min", "hour", "mday", "mon",
"year", "wday", "yday", "isdst"), class = c("POSIXlt", "POSIXt"
))), .Names = c("start", "end", "value", "time"), row.names = c(NA,
-4L), class = "data.frame")