How to create a pivot table from this table, Part 2
2 次查看(过去 30 天)
显示 更早的评论
To generalize https://www.mathworks.com/matlabcentral/answers/898782-how-to-create-a-pivot-table-from-this-table-revised?s_tid=srchtitle,
suppose I have a table T
location gender sales
-----------------------------------------------------------
Customer 1 NY male 10
Customer 2 LA female 20
Customer 3 Austin female 15
Customer 4 LA female 10
Then I want to create a pivot table
Male sales Female sales
--------------------------------------------
NY 10 0
LA 0 30
Austin 0 15
I checked unstack and grpstat but I am not sure. What will be a next step?
0 个评论
采纳的回答
Stephen23
2021-8-21
customer = {'Customer 1';'Customer 2';'Customer 3';'Customer 4'};
location = {'NY';'LA';'Austin';'LA'};
gender = {'male';'female';'female';'female'};
sales = [10;20;15;10];
T = table(customer,location,gender,sales)
S = removevars(T,'customer');
S = groupsummary(S,{'location','gender'},'sum')
U = unstack(S,'sum_sales','gender')
etc.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!