필터 지우기
필터 지우기

calculations in levels ( per name and rank)

조회 수: 1 (최근 30일)
Vanessa
Vanessa 2017년 9월 22일
댓글: Vanessa 2017년 9월 22일
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'})
  댓글 수: 3
Vanessa
Vanessa 2017년 9월 22일
The results are wrong. I get larger results than the true ones. How can I fix this??
Vanessa
Vanessa 2017년 9월 22일
Sorry my mistake

댓글을 달려면 로그인하십시오.

카테고리

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