%% Fill Missing Data by Group
% Create a timetable containing a progress status for 3 teams.

timeStamp = days([1 1 1 2 2 2 3 3 3]');
teamNumber = [1 2 3 1 2 3 1 2 3]';
percentComplete = [14.2 28.1 11.5 NaN NaN 19.3 46.1 51.2 30.3]';
T = timetable(timeStamp,teamNumber,percentComplete)

% Fill missing status percentages (NaN) for each group using linear interpolation.

G = grouptransform(T,'teamNumber','linearfill','percentComplete')

% To append the filled data to the original table instead of replacing the percentComplete variable, use the 'ReplaceValues' parameter.

Gappend = grouptransform(T,'teamNumber','linearfill','percentComplete','ReplaceValues',false)

% Copyright 2018 The MathWorks, Inc.