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

조회 수: 17 (최근 30일)
MR
MR 2021년 11월 14일
답변: Seth Furman 2021년 11월 16일
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!

답변 (2개)

Chunru
Chunru 2021년 11월 14일
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 2021년 11월 16일

카테고리

Help CenterFile Exchange에서 MATLAB Mobile에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by