试图计算两个两列之间的时间差,但是“difftime”中的时间 2 在 next.row
sample data:
structure(list(code = c(10888, 10888, 10888, 10888, 10888, 10888,
10889, 10889, 10889, 10889, 10889, 10889, 10890, 10890, 10890
), station = c("F1", "F3", "F4", "F5", "L5", "L7", "F1", "F3",
"F4", "L5", "L6", "L7", "F1", "F3", "F5"), a = structure(c(1365895151,
1365969188, 1366105495, 1367433149, 1368005216, 1368011698, 1366244224,
1366414926, 1367513240, 1367790556, 1367946420, 1367923973, 1365896546,
1365907968, 1366144207), class = c("POSIXct", "POSIXt"), tzone = ""),
b = structure(c(1365895316, 1365976904, 1366105495, 1367436539,
1368005233, 1368033855, 1366244224, 1366415643, 1367513840,
1367915506, 1367946597, 1367954061, 1365897164, 1365907968,
1366157867), class = c("POSIXct", "POSIXt"), tzone = "")), .Names = c("code",
"station", "a", "b"), row.names = 2:16, class = "data.frame")
我想计算a列第一行和b列第二行之间的时间。
Difftime 很简单:
difftime(test$a, test$b)
但是我正在努力获得下一行,尝试过:
difftime(test$a, c(test, b[seq_len(.N+1)])[])
和这个主题的变化,但无济于事。
最后,我将通过=代码进行计算,因此仅在具有相同代码的值之间计算差异时间。可能使用ddply?或,按=代码。