## Timetable Monthly Average over Many Years

### Nathan Gjersvik (view profile)

on 2 Oct 2019
Latest activity Commented on by Nathan Gjersvik

on 3 Oct 2019

### Guillaume (view profile)

I have a daily precipitation data file with two columns.The first column is "date", with date format yyyy-mm-dd and the second column is "precip" with double format. My data ranges from 1980-01-01 to 2010-12-31, and I would like to determine the average precipitation values for each month over that interval.
Example of desired result:
Month avgPrecip
Jan 0.0056
Feb 0.0034
...
for each month.
I have attached my csv file with the data and my current progess. I can get the monthly average of the data within each year using a timetable and retime, but I am stuck trying to average the monthly average data for the entire data range. Thank you!
precip = table2timetable(precip);
monthlyAvg = retime(precip,'monthly','mean');

R2018a

### Guillaume (view profile)

on 2 Oct 2019

The easiest:
monthlyavg = groupsummary(precip, 'day', 'monthofyear', 'mean')

Nathan Gjersvik

### Nathan Gjersvik (view profile)

on 3 Oct 2019
This works and is very simple! Thank you very much!

### QuanCCC (view profile)

on 2 Oct 2019

you can simply make another column of year-month-day-time, merge it to your data. Then transform it to timetable, time column will be your new column. Then use the same 'monthly','mean' on all months.
t1 = datetime(1980,01,01,12,0,0);
t2 = datetime(2010,12,31,12,0,0);
t = t1:t2;
t = t';
clear t1 t2
NewData = timetable(t, YourOldData); % merge data
MonthlyAve = retime(NewData, 'monthly', 'mean');

on 3 Oct 2019