Dayname for year using groupsummary

1 visualización (últimos 30 días)
Ajay Nair
Ajay Nair el 7 de Mayo de 2020
Respondida: TARUN el 8 de Ag. de 2025
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.

Respuestas (1)

TARUN
TARUN el 8 de Ag. de 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:

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by