I am working with smart meter data which is in half-hourly resolution. Due to the sheer volume of data I am trying to reduce from half-hourly resolution to hourly resolution. In doing so I am attempting to sum the consumption between two half-hourly measurements. The issue is I also have catagorical data in my data frame which I lose when using xts. This is what my data looks like:
> head(test1)
LCLid stdorToU DateTime KWH.hh..per.half.hour. Acorn Acorn_grouped
1 MAC000002 Std 2012-10-12 00:30:00 0 ACORN-A Affluent
2 MAC000002 Std 2012-10-12 01:00:00 0 ACORN-A Affluent
3 MAC000002 Std 2012-10-12 01:30:00 0 ACORN-A Affluent
4 MAC000002 Std 2012-10-12 02:00:00 0 ACORN-A Affluent
5 MAC000002 Std 2012-10-12 02:30:00 0 ACORN-A Affluent
6 MAC000002 Std 2012-10-12 03:00:00 0 ACORN-A Affluent
Here is the code I have been attempting to use and the result I get.
test1 <- read.csv("test.csv", stringsAsFactors = F)
test1$DateTime <- ymd_hms(test1$DateTime)
test1$KWH.hh..per.half.hour. <- as.numeric(test1$KWH.hh..per.half.hour.)
test2 <- xts(test1$KWH.hh..per.half.hour., test1$DateTime)
head(test2)
period.apply(test2, endpoints(test2, "hours"), sum)
> period.apply(test2, endpoints(test2, "hours"), sum)
[,1]
2012-10-12 00:30:00 0.000
2012-10-12 01:30:00 0.000
2012-10-12 02:30:00 0.000
2012-10-12 03:30:00 0.000
2012-10-12 04:30:00 0.000
2012-10-12 05:30:00 0.000
2012-10-12 06:30:00 0.000
2012-10-12 07:30:00 0.000
2012-10-12 08:30:00 0.000
2012-10-12 09:30:00 0.000
2012-10-12 10:30:00 0.000
Ideally, I need a data set exactly as my original (test1), just half the size aggregated to hourly frequency rather than half-hourly. Can someone please help.
Thanks