calculations in levels ( per name and rank)

1 次查看(过去 30 天)
Hello everyone,
I have a dataset array with names,ranks and durations
[Name] [Rank] [Duration]
[xxxx ] [ MAS ] [6]
[xxxx] [MAS] [5]
[yyyy] [MAS] [5]
[yyyy] [MAS] [4]
[yyyy] [CO] [7]
[yyyy] [CO] [6]
xxxx 1st person
yyyy 2nd person
I want to calculate the sum of durations per name and per rank
1st person : 11 months as MAS
2nd person: 9 months as MAS and 13 months as CO
How can I achieve this?

回答(1 个)

Guillaume
Guillaume 2017-9-22
编辑:Guillaume 2017-9-22
[group, idname, idrank] = findgroups(yourdataset.Name, yourdataset.Rank);
result = table(idname, idrank, splitapply(@sum, yourdataset.Duration, group), 'VariableNames', {'Name', 'Rank', 'TotalDuration'})

类别

Help CenterFile Exchange 中查找有关 Interpolation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by