title: dateTime changes from POSIXct to factor when averaging - R
body: <p>I have the following example:</p>
  
  <pre><code>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)
  })
  </code></pre>
  
  <p>I wish to calculate the hourly averages, so I use:</p>
  
  <pre><code>data &lt;- aggregate(dat[colnames(dat)[2:length(colnames(dat))]],
                    list(dateTime = cut(dat$dateTime,breaks = "hour")),
                    mean,
                    na.rm = TRUE)
  </code></pre>
  
  <p>However, the class of the dateTime column has changed from POSIXct to factor:</p>
  
  <pre><code>&gt; class(dat$dateTime)
  [1] "POSIXct" "POSIXt" 
  &gt; class(data$dateTime)
  [1] "factor"
  </code></pre>
  
  <p>Why is this the case, and how can I change it back to be POSIXct?</p>