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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

javascript - Clean way to programmatically use CSS transitions from JS? -

android - send complex objects as post php java -