Search code examples
raggregate

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

  • (Since the user (@user20650) who answered added it as a comment, I am answering my own question)

    aggregate(Amount ~ format(as.POSIXct(countByCountryTime$theTime24), "%Y-%m-%d %H"), data=countByCountryTime, sum)