Average of variables in timetable belonging to the same day over several years
18 ビュー (過去 30 日間)
Hello, I have a timetable, TT(681-by-19), with unevenly spaced daily data from 2010 to 2020 and 19 variables (there might be days that do not occur every year in addition to gaps where entire months are missing). I want to calculate the mean of the variables that correspond to the same day throughout the different years. For example I want to calculate the mean of each of the 19 variables that correspond to 25-oct 2010, 25-oct 2011, ..., 25-oct 2020 and so on for the different dates. That way I would have each unique day-month occurring only once in the output.
Note: I also have the dates seperately as a datetime array and as a numeric array in the form of yyyymmdd (681-by-1) and the 19 variables in a numeric array (681-by-19), if there is a simpler method without the use of the timetable.
Thanks for any assistance.
Peter Perkins 2022 年 8 月 25 日
Ziad, it seems that "dayofyear" is using "serial day number of year", and as you found, is lumping 29-Feb's with the non-leap 1-Mar's, etc. What you want is to group by month/day. If you use the month and day of month as grouping vars, you get what you want:
dt = [datetime(2012,2,27:31) ...
x = dt.Day;
tt = timetable(x,RowTimes=dt)
tt.Month = string(month(tt.Time,"name"));
tt.Day = day(tt.Time,"dayofmonth");
means = groupsummary(tt,["Month" "Day"],"mean","x")