我有以下示例:
begin_date = as.POSIXlt("1990-01-01", tz = "GMT")
# 30 year dataset
dat = data.frame(dateTime = begin_date + (0:(24*30*20)) * (1800))
dat = within(dat,{speed = runif(length(dateTime), 1, 10)
})
我希望计算每小时平均值,所以我使用:
data <- aggregate(dat[colnames(dat)[2:length(colnames(dat))]],
list(dateTime = cut(dat$dateTime,breaks = "hour")),
mean,
na.rm = TRUE)
但是,dateTime 列的类已从 POSIXct 更改为 factor:
> class(dat$dateTime)
[1] "POSIXct" "POSIXt"
> class(data$dateTime)
[1] "factor"
为什么会这样,我怎样才能把它改回 POSIXct?