%% Group by Table Variables
% Calculate mean blood pressures for patients using grouping variables that are in a table.
% Load gender and smoking data for 100 patients into a table.

load patients
T = table(Gender,Smoker);
T(1:5,:)

%
% Specify groups of patients using the Gender and Smoker variables in T.

G = findgroups(T);

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

meanSystolic = splitapply(@mean,Systolic,G);
meanDiastolic = splitapply(@mean,Diastolic,G);
mBP = [meanSystolic,meanDiastolic]

% Copyright 2015 The MathWorks, Inc.