I have a data set with "UI" measurements every 4 hours for each day, for 7 years. I need to transform the hourly data into daily data, calculating the mean of every 4 hours for all the years.
The data set looks like this:
# A tsibble: 10,225 x 6 [6h] <UTC>
Ano Mes Dia Hora UI Date
<dbl> <dbl> <dbl> <dbl> <dbl> <dttm>
1 2012 1 1 0 37.9 2012-01-01 00:00:00
2 2012 1 1 6 9.18 2012-01-01 06:00:00
3 2012 1 1 12 1.18 2012-01-01 12:00:00
4 2012 1 1 18 27.0 2012-01-01 18:00:00
5 2012 1 2 0 -292. 2012-01-02 00:00:00
6 2012 1 2 6 98.2 2012-01-02 06:00:00
7 2012 1 2 12 95.9 2012-01-02 12:00:00
8 2012 1 2 18 6.19 2012-01-02 18:00:00
9 2012 1 3 0 -4.65 2012-01-03 00:00:00
10 2012 1 3 6 40.1 2012-01-03 06:00:00
# ... with 10,215 more rows
I used the function aggregate:
dados<-aggregate(dados2018$UI,by=list(dados2018$Dia),median)
But it gave me the median for each day for all the months and all the years together. I need only the daily median for all the days of every month, in every year.
Thank you for the help!