Summary Statistics Table by group

24 次查看(过去 30 天)
mo
mo 2018-10-25
回答: Steven Lord 2018-10-25
Hi,
I'm new in Matlab and I'm completely lost. I would like to create a table of summary statistics (mean, median, mode, std, max, min, skewness, kurtosis) of different caracteristics such as Common Equity Tier 1 ratio, Leverage ratio..... I imported my data form my excel folder. I already create and define my variables.
Here is my code : %Create and define my date data.return1018=data.data(:,1); data.return1w=data.data(:,2); data.LVGR0617=data.data(:,3); data.CET1R0617=data.data(:,7); data.TLRE0617=data.data(:,11); data.NPA0617=data.data(:,25); data.OBS0617=data.data(:,27);
dsa=({'data.CET1R0617', 'data.LVGR0617', 'data.NPA0617', 'data.OBS0617', 'data.return1w', 'data.return1018'})
statarray = grpstats(dsa,{'mean','median','mode','std','min','max','skewness','kurtosis'})
The problem is that my group stats doesn't work... and I really don't know why.
Thank you in advance for your help,
  1 个评论
jonas
jonas 2018-10-25
Well, your syntax is wrong and it's not possible to help you with the limited information you have provided. What is dsa? Why is the table not passed to the function? Are all your variables numeric?
Would be easier if you just uploaded your table.

请先登录,再进行评论。

回答(2 个)

jonas
jonas 2018-10-25
You need to pass the table as input to grpstats. Assuming that dsa is a cell array with grouping variables, then change your code as follows:
dsa = {'CET1R0617', 'LVGR0617', 'NPA0617', 'OBS0617', 'return1w', 'return1018'}
statarray = grpstats(data,dsa,{'mean','median','mode','std','min','max','skewness','kurtosis'})

Steven Lord
Steven Lord 2018-10-25
Instead of reading your data into a matrix and post-processing to create a struct from that matrix, consider using readtable to read the data directly into a table array.
Once you have your data in a table use groupsummary with one or more of your table variables as a grouping variable, or use findgroups and splitapply, or depending on the specific summary statistics you want to generate call summary on the table.

类别

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

Community Treasure Hunt

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

Start Hunting!

Translated by