%% Group by Month
% Create a table of dates and corresponding profits.

timeStamps = datetime([2017 3 4; 2017 3 2; 2017 3 15; 2017 4 10;...
                       2017 4 14; 2017 4 30; 2017 5 25;...
                       2017 5 29; 2017 5 21]);
profit = [2032 3071 1185 2587 1998 2899 3112 909 2619]';
T = table(timeStamps,profit)

%
% Group the dates by month, and return only rows that correspond to the maximum profit for that month.

Gmax = groupfilter(T,'timeStamps','month',@(x) x == max(x))

%
% Return rows whose month had an average profit greater than $2300.

Gavg = groupfilter(T,'timeStamps','month',@(x) mean(x) > 2300)

% Copyright 2019 The MathWorks, Inc.