В базе R разделить на те значения, где as.POSIXct
дает NA
, затем rbind
результат.
res <- do.call(rbind.data.frame,
by(x, cumsum(is.na(as.POSIXct(x, format="%T"))), function(x)
cbind(as.character(x)[1], as.character(x)[-1])))
head(res)
# V1 V2
# 1.1 10000007 01:33:28
# 1.2 10000007 00:00:05
# 2.1 10000010 00:00:39
# 2.2 10000010 00:02:21
# 2.3 10000010 00:05:59
# 2.4 10000010 00:40:40
Данные:
x <- structure(c(31L, 30L, 4L, 32L, 8L, 11L, 16L, 24L, 21L, 33L, 19L,
1L, 6L, 3L, 25L, 34L, 26L, 29L, 35L, 27L, 28L, 36L, 9L, 12L,
15L, 7L, 2L, 13L, 5L, 10L, 18L, 22L, 23L, 20L, 17L, 14L), .Label = c("00:00:00",
"00:00:01", "00:00:02", "00:00:05", "00:00:10", "00:00:15", "00:00:29",
"00:00:39", "00:00:58", "00:01:08", "00:02:21", "00:03:42", "00:04:02",
"00:04:29", "00:05:58", "00:05:59", "00:07:48", "00:07:52", "00:09:37",
"00:09:39", "00:09:53", "00:10:18", "00:12:52", "00:40:40", "00:40:51",
"00:41:44", "01:07:14", "01:25:27", "01:32:32", "01:33:28", "10000007",
"10000010", "10000014", "10000022", "10000023", "1000003"), class = "factor")