필터 지우기
필터 지우기

Unstack: how to create a pivot table like this?

조회 수: 3 (최근 30일)
alpedhuez
alpedhuez 2020년 7월 3일
답변: Monisha Nalluru 2020년 7월 7일
I have a table like (the real table is more complicated)
date month person spending
--------------------------
1/1/2020 January John 30
1/1/2020 January Mike 15
1/2/2020 January John 20
1/3/2020 January Kate 30
I want to create a pivot table like
month John's share of spending out of total spending | Mike's share | Kate's share
------------------------------------------
January
February
Please advise.
  댓글 수: 1
alpedhuez
alpedhuez 2020년 7월 3일
first create a pivot table with spending of each and then calculate shares

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

채택된 답변

Monisha Nalluru
Monisha Nalluru 2020년 7월 7일
The following might be of help to you
  • Unstack function can be used to create the required model
  • The share is calculated as (amount/ total amount) *100 can be month or yearly
To display share for whole year , you can make use of this example
month = categorical({'Jan';'Jan';'Jan';'Jan'});
person = categorical({'John';'Mike';'John';'Kate'});
spendings = [30;15;20;30];
totalamount=sum(spendings);
share=[spendings/totalamount]*100;
T = table(month,person,share);
u = unstack(T,'share','person')
You can customize the data accordingly

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by