(我've read many similar problems, but could not find an answer to my problem, even though it seems trivial; I just don't看问题的原因)

我有时间标记的测量(带有一些基于偏移的数字时间戳),我想在不同的时间间隔聚合进行分析 . 为了便于阅读,我将时间戳转换为人类可读的(使用带有 origintz="UTC" 参数的 as.POSIXlt() ) .

在整数值 cut() 运行良好,但我没有让它适用于 POSIXlt 值 . 根据手册(以及我发现的一些答案),它应该是开箱即用的 .

Browse[1]> str(cols$time)
List of 39531
 $ : POSIXct[1:1], format: "2016-07-05 00:00:58"
 $ : POSIXct[1:1], format: "2016-07-05 00:02:02"
 $ : POSIXct[1:1], format: "2016-07-05 00:03:06"
 $ : POSIXct[1:1], format: "2016-07-05 00:04:10"
 $ : POSIXct[1:1], format: "2016-07-05 00:05:14"
 $ : POSIXct[1:1], format: "2016-07-05 00:06:18"
[...]
 $ : POSIXct[1:1], format: "2016-07-05 01:44:26"
 $ : POSIXct[1:1], format: "2016-07-05 01:45:30"
  [list output truncated]
Browse[1]> cut(cols$time, breaks="5 min")
Fehler in cut.default(cols$time, breaks = "5 min") : 
  'x' muss numerisch sein
Browse[1]> cut.POSIXt(cols$time, breaks="5 min")
Fehler in cut.POSIXt(cols$time, breaks = "5 min") : 
  'x' muss ein date-time Objekt sein
Browse[1]>

(抱歉德语区域设置(和错误消息))我希望R将总时间间隔细分为 n 等长间隔或特定持续时间间隔 .

Additional Info:

我写了这个辅助函数(实际上数学有点复杂,但原理是这样的):

POSIX <- function(day, offset) {
    origin <- "1970-01-01 00:00:00"
    return(as.POSIXlt(day * 86400 + offset, origin=origin, tz="UTC"))
}

(在一天内收到日期编号和偏移量,返回 POSIXlt 时间戳)

最终时间戳本身是在双向过程中创建的:

for (d in dayLevels) {
    days[[d]] <- POSIX(as.numeric(d), 0)
}

cols$time <- lapply(1:rows, function(i) return(cols$day[[i]] + cols$time[i])

(我正在向 POSIXlt 添加小数秒)