I have an xts object that includes multiple parameters over a 24 hour period (measurements each minute). Based on the time, I have added a column grouping into 4 'time of day' (tod) options: 'morning', 'afternoon', 'evening' and 'night'.
I would like to extract the mean values and standard deviations of the columns (parameters) for the entire period and also by time of day ('tod').
I have tried to first convert the xts object to a data frame, but have problems with the columns being of class factor instead of numeric. I have also tried 'aggregate' but am getting really strange outputs (or errors) when I use aggregate. Here is an example:
eg code to create a much smaller version of my data:
# time vector:
Time <- ISOdatetime(2015,01,01,6,12,0) + seq(0:(0.5*60-1))*1*60
# sample parameter columns
a <- 1:30
b <- 31:60
c<-seq(1,90,3)
# a sample xts object 'tester'
tester <- xts(cbind(a,b,c),Time)
# assign 'time of day':
tester$tod <- NA
tester$tod["T06:00/T06:20"]<-"night"
tester$tod["T06:21/T11:30"]<-"morning"
tester$tod["T06:31/T06:50"]<-"afternoon"
eg of how I have tried to get the mean values for a, b, c both for all data and by 'tod' using 'aggregate' (note that there are NA's in my data but this is not the issue):
tester$group = 1 #create a group column just to get the means for all data
mean_all <- aggregate(.~group, data=tester, FUN=mean, na.rm = TRUE, na.action=NULL)
meann_tod <- aggregate(.~tod, data=tester, FUN=mean, na.rm = TRUE, na.action=NULL)
Unfortunately this does not work, although there are no errors, the values are completely wrong.
Any advice would be much appreciated, I imagined this would be a very simple task!