I have a table where multiple columns have NaN and I want the NaN to be replaced by the previous valid value in the column, within the group(by ID.
T = ID amount1 amount2 15 200 300 15 NaN 800 15 NaN NaN 67 NaN 300 67 400 700 67 NaN NaN
Expected output:
ID amount1 amount2 15 200 300 15 200 800 15 200 800 67 NaN 300 67 400 700 67 400 700
I am able to achieve this partially using fillmissing function as:
Tupdated = fillmissing(T,'previous');
But I want to implement this within group (by ID). I am unable to use fillmissing with splitapply correctly.
Best Answer