%% Multiple Grouping Variables
% Group table data using two grouping variables.
% Create a table T that contains information about five individuals.

Gender = ["male";"female";"male";"female";"male"];
Smoker = logical([1;0;1;0;1]);
Weight = [176;163;131;133;119];
T = table(Gender,Smoker,Weight)

% Compute the mean weight, grouped by gender and smoking status. By default, two combinations of gender and smoking status are not represented in the output because they are empty groups.

G = groupsummary(T,{'Gender','Smoker'},'mean','Weight')

% Set the 'IncludeEmptyGroups' parameter value to true in order to see all group combinations, including the empty ones.

G = groupsummary(T,{'Gender','Smoker'},'mean','Weight','IncludeEmptyGroups',true)

% Copyright 2012 The MathWorks, Inc.