How to find missing values in a table and delete the row along with all other associated rows
14 ビュー (過去 30 日間)
古いコメントを表示
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.
0 件のコメント
採用された回答
Cris LaPierre
2021 年 7 月 2 日
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,:) = [];
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!