I have data for temperature measurements every 15 minutes for a whole year. I've calculated the average temperature for these hours over the course of the year. What I wish to calculate though, is the average per hour rather than per 15 minutes.
What I currently calculated is:
Hour Average_Temperature
1 0:00:00 14.35748
2 0:15:00 14.30943
3 0:30:00 14.18519
4 0:45:00 14.04781
5 1:00:00 13.93074
6 1:15:00 13.78855
7 1:30:00 13.67138
8 1:45:00 13.54646
I've achieved the first table using simply the package dplyr
. I call group_by()
on the Hour
variable and then call in summarise()
.
AvgHr <- mydata %>%
group_by(Hour) %>%
summarise(Average_Temperature = mean(Temp))
What I do not know how to do is whether I can do a nested grouping where I group and then average per full hour rather than per individual quarter hour. In the table above I would then consider the values for observation 0:00:00, 0:15:00, 0:30:00, 0:45:00 under the same observation of 0:00:00.
What I would then get, would be the following:
Hour Average_Temperature
1 0:00:00 14.xxxxx
2 1:00:00 13.xxxxx
3 2:00:00 13.xxxxx