%% Apply Function to Groups Within Timetable Variables
% Create a timetable containing sample data. The row times of the timetable also define groups.

dt = datetime(2016,1,1)+days([0 1 1 2 3 3])';
A = timetable(dt,[0.71;-2.05;-0.35;-0.82;1.57;0.09],...
              [0.23;0.12;-0.18;0.23;0.41;0.02],...
              'VariableNames',{'x' 'y'})

%
% Compute the group-wise means of the variables in the timetable. varfun returns B as a timetable because A is a timetable. When you specify the row times as the grouping variable, you cannot specify any variable as another grouping variable.

B = varfun(@mean,A,'GroupingVariables','dt')

% Copyright 2012 The MathWorks, Inc.