I recommend you check out xts
package which is very good for any time series analysis.
Following example will show how you can get sums over any periodicity
require(xts)
#Convert data to xts format
dat.xts <- xts(dat$Demand, order.by = as.POSIXct(dat$Date, format = "%m/%d/%Y %H:%M:%S"))
period.sum(x = dat.xts, INDEX = endpoints(dat.xts, on = "hours"))
## [,1]
## 2012-01-01 00:55:00 59560.6
## 2012-01-01 01:00:00 4860.4
More generic example below showing how you can apply any function over any periodicity
period.apply(dat.xts, INDEX = endpoints(dat.xts, on = "mins", k = 20), FUN = "sum")
## [,1]
## 2012-01-01 00:15:00 20086.5
## 2012-01-01 00:35:00 19875.1
## 2012-01-01 00:55:00 19599.0
## 2012-01-01 01:00:00 4860.4
In above examples endpoints
function create INDEX
of end points of periods over which you want to apply any function.