Combining Rows of a Table based on Matching first column entry?

34 visualizaciones (últimos 30 días)
MR
MR el 14 de Nov. de 2021
Respondida: Seth Furman el 16 de Nov. de 2021
I have a table with data of coaches from different schools and I want to combine rows that have matching school names. I'm not sure if there's a way to do this without looping but that would be ideal for me. Below is what a section of the Table looks like:
School Year Games Wins Losses
'Air Force' 2011 13 7 6
'Akron' 2011 12 1 11
'Alabama' 2011 13 12 1
'Arizona' 2011 6 3 3
'Arizona' 2011 6 1 5
'Arizona State' 2011 13 6 7
I would like to have the table look like this below (Combining the Row 'Arizona'):
School Year Games Wins Losses
'Air Force' 2011 13 7 6
'Akron' 2011 12 1 11
'Alabama' 2011 13 12 1
'Arizona' 2011 12 4 8
'Arizona State' 2011 13 6 7
Again, this is only 6 rows of the table, but there are ~130 total rows in the table with up to 20 rows that need to be combined into 10 rows. Any help/advice would be appreciated! Thanks in advance!

Respuestas (2)

Chunru
Chunru el 14 de Nov. de 2021
Tcell ={'Air Force' 2011 13 7 6
'Akron' 2011 12 1 11
'Alabama' 2011 13 12 1
'Arizona' 2011 6 3 3
'Arizona' 2011 6 1 5
'Arizona State' 2011 13 6 7};
T = cell2table(Tcell);
T.Properties.VariableNames = {'School' 'Year' 'Games' 'Wins' 'Losses'};
groupsummary(T, {'School', 'Year'}, 'sum')
ans = 5×6 table
School Year GroupCount sum_Games sum_Wins sum_Losses _________________ ____ __________ _________ ________ __________ {'Air Force' } 2011 1 13 7 6 {'Akron' } 2011 1 12 1 11 {'Alabama' } 2011 1 13 12 1 {'Arizona' } 2011 2 12 4 8 {'Arizona State'} 2011 1 13 6 7

Seth Furman
Seth Furman el 16 de Nov. de 2021

Categorías

Más información sobre Just for fun en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by