Following from this question: How can I calculate average hour of an event? where we wanted to compute the average circular mean and median, how would one calculate the difference between each time point and the mean? Would it be enough to subtract each data point from the mean? The code below doesn't work. The goal is to achieve something along the lines of - if there are two data points 22 and 1 and the circular mean is 23, then the first point is one hour early and the second is two hours past, so -1 and +2. But I don't know if this is the best way of computing time differences when considering the circular nature of clock time.
library(circular)
hours <- c(1, 20.10, 21, 22, 23 , 0, 1, 2.5)
hours.circ <- circular(hours, template = "clock24", units = "hours")
mean.circ <- mean(hours.circ)
as.numeric(mean.circ) %% 24
## [1] 0
median.circ <- median(hours.circ)
as.numeric(median.circ) %% 24
## [1] 0
plot(hours.circ)
points(mean.circ, col = "red", cex = 3)
points(median.circ, col = "blue", cex = 2)
for (i in hours.circ){
x = as.numeric(hours.circ - mean.circ)%% 24
print(x)
}