Combining Rows of a Table based on Matching first column entry?
26 次查看(过去 30 天)
显示 更早的评论
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!
0 个评论
回答(2 个)
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')
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!