How to find missing values in a table and delete the row along with all other associated rows

14 views (last 30 days)
I have a imported data into a table named V in MATLAB. The first column contains dates in the form 01/01/1987 00:00, everyday for 31 years. The other columns are variables.
Some of the variables data is missing in column 3 (NaN in the cells) and I would like to delete all rows with missing data but also then check what year that row was and delete all other rows of the same year.
There are too many rows to do this by inspection so I cannot use rmmissing(V) as I won't be able to check what was deleted and then delete all other rows of the same year. By the same reason I also cannot use:
V(V.(3) == 0, :) = [];
Any help would be much appreciated.

Accepted Answer

Cris LaPierre
Cris LaPierre on 2 Jul 2021
It seems a solution will need to be highly customized to your particular data set. Since you haven't shared your data, here's my best guess.
% Find rows missing data in var3
ind = ismissing(V.(3));
% Extract the year corresponding to missing data
yr = unique(year(V{ind,1}));
% Find rows of table from same years as missing data
rm = ismember(year(V.(1)),yr);
% delete
V(rm,:) = [];

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!