dateTime changes from POSIXct to factor when averaging - R -
i have following example:
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) })
i wish calculate hourly averages, use:
data <- aggregate(dat[colnames(dat)[2:length(colnames(dat))]], list(datetime = cut(dat$datetime,breaks = "hour")), mean, na.rm = true)
however, class of datetime column has changed posixct factor:
> class(dat$datetime) [1] "posixct" "posixt" > class(data$datetime) [1] "factor"
why case, , how can change posixct?
data$datetime <- as.posixct(as.character( data$datetime))
Comments
Post a Comment