'Aggregate time column on hourly interval in R

I have a df in R in the following format. What could be the easiest way to aggregate this on an hourly time interval basis, currently it is every minute

                 theTime24 Amount
988 2015-02-04 23:53:00      2
989 2015-02-04 23:55:00      1
990 2015-02-04 23:56:00      3
991 2015-02-04 23:57:00      2
992 2015-02-04 23:58:00      1
993 2015-02-04 23:59:00      2


Solution 1:[1]

I would format the date as POSIX, convert to hourly, and aggregate.

 dt$theTIME24<-as.POSIXct(strptime(dt$theTIME24,format="%Y-%m-%d %H:%M:%S"))
 dt$theTIME24.h<-as.POSIXct(strptime(dt$theTIME24,format="%Y-%m-%d %H"))
 amt<-aggregate(dt$Amount,by=list(dt$theTIME24.h),mean)

Solution 2:[2]

Please try this:

library(foqat)
trs(df, "1 hour")

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jsta
Solution 2 TichPi