%% Filter Three-Variable Table
% Create a table containing three variables.

groupID = [1 2 3 1 2 3 1 2 3]';
height = [62 61 59 66 70 72 57 67 71]';
gender = ["M" "F" "F" "M" "M" "F" "M" "M" "M"]';
T = table(groupID,height,gender)

% Group by ID number, and return rows whose group members all have a minimum height of 60.

G1 = groupfilter(T,'groupID',@(x) min(x) >= 60,'height')

% Return rows whose group members are all male.

G2 = groupfilter(T,'groupID',@(x) all(x == "M"),'gender')

% Group by ID number and gender, and return rows containing the maximum height for males and females in each group.

G3 = groupfilter(T,{'groupID','gender'},@(x) x == max(x))

% Copyright 2019 The MathWorks, Inc.