%% Group from Table and Create Output Table
% Create a table of mean blood pressures for patients grouped by gender and status as a smoker or nonsmoker.
% Load gender and smoking data for patients into a table.

load patients
T = table(Gender,Smoker);

%
% Specify groups of patients using the Gender and Smoker variables in T. The output table TID identifies the groups.

[G,TID] = findgroups(T);
TID

%
% Calculate mean blood pressures from the data variables Systolic and Diastolic. Append mean blood pressures to TID.

TID.meanSystolic = splitapply(@mean,Systolic,G);
TID.meanDiastolic = splitapply(@mean,Diastolic,G)

% Copyright 2015 The MathWorks, Inc.