How to group data according to date in years?
11 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Marcel345614
le 25 Jan 2022
Commenté : Star Strider
le 25 Jan 2022
I have a table with data of specific days of the year over a range of 10 years, e.g.
1.Jan.2013 12
8.Jan.2013 10
...
23.May.2013 15
30.May.2013 12
...
8.Nov.2013 5
...
1.Jan.2014 16
8.Jan.2014 11
...
23.May.2014 11
30.May.2014 10
...
23.May.2015 8
30.May.2015 9
...
(in other words: I have data over a period of 10 years of the 1.Jan,8.Jan,....,23.May,30.May,.....8.Nov,...)
Now I would like to have a groupsummary according to these dates over all the years, e.g.
Date mean func1 median etc.
1.Jan 11 6 4
8.Jan 10 5 3
...
23.May 9 5 10
...
In the end I would like to plot all the function values (mean, median, func1) over Date (1.Jan, 8.Jan, ...,23.May,... on x-axis).
How can I achieve this?
I tried with 'dayofyear', but this is a bit annoying because of leap years...
0 commentaires
Réponse acceptée
Star Strider
le 25 Jan 2022
Since 'dayofyear' won’t work, break the dates down into two new variables, specifically the day and the month, then group on them. To get them back to the 'dd.MMM' format requires a bit of creativity, however it can be done —
T1 = table({'1.Jan.2013'; '8.Jan.2013'; '1.Jan.2014'; '8.Jan.2014'}, [12; 10;, 16; 11], 'VariableNames',{'Date','Something'})
T1.Var1 = datetime(T1.Date, 'InputFormat','dd.MMM.yyyy','Format','dd.MMM.yyyy')
T1.Day = day(T1.Date);
T1.Month = month(T1.Date)
G1 = groupsummary(T1,{'Day','Month'},{'mean','median','std',@(x)std(x)/sqrt(numel(x))},'Something')
G1.DayMonth = datetime(zeros(size(G1.Month)),G1.Month,G1.Day, 'Format','dd.MMM')
G1.Properties.VariableNames{end-1} = 'StdErrMean_Something';
G2 = G1(:,[end 3 4:end-1])
Add other summary statistics as desired.
With respect to plotting them, see Plot Dates and Durations for a complete dsescription of the process.
.
2 commentaires
Star Strider
le 25 Jan 2022
As always, my pleasure!
This is an interesting problem. Thank you for posting it!
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!