Dayname for year using groupsummary
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
i have table for 1 full year.
i need to regroup table into dayname for each month.
if i use
groupsummary(MyTable, 'Date_Time', 'dayname', @nanmean);
am getting 7 days averaged for 1 year but i need it for indvidual months like each month days are averaged.
final output should be 7 rows 12 colums.
7 represnts dayname 12 represents each month.
0 commentaires
Réponses (1)
TARUN
le 8 Août 2025
The reason you are getting just 7 rows is because
groupsummary(MyTable, 'Date_Time', 'dayname', @nanmean);
averages across the entire year.
To get weekday averages for each month (a 7×12 matrix), you’ll need to group by both day name and month.
You can use the following workaround to fix it:
MyTable.Month = month(MyTable.Date_Time);
MyTable.DayName = categorical(day(MyTable.Date_Time, 'longname'));
Summary = groupsummary(MyTable, {'DayName', 'Month'}, 'nanmean');
Result = unstack(Summary, 'nanmean_YourVar', 'Month');
‘YourVar’ is the variable that you are using for averaging.
This gives you 7 rows (Mon–Sun) and 12 columns (Jan–Dec), just as needed.
Please refer to this documentation for more details:
0 commentaires
Voir également
Catégories
En savoir plus sur Tables dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!