Remove rows with NaN from a table

89 ビュー (過去 30 日間)
alpedhuez
alpedhuez 2018 年 6 月 13 日
コメント済み: Blake 2019 年 9 月 19 日
I have a table T. T has some rows with NaN. I would like to remove any rows with NaN in any entry. Please advise.

採用された回答

Paolo
Paolo 2018 年 6 月 13 日
Use rmmissing :
T = table([38;43;38;40;49],[71;NaN;64;67;64],[176;163;131;NaN;119])
T =
Var1 Var2 Var3
____ ____ ____
38 71 176
43 NaN 163
38 64 131
40 67 NaN
49 64 119
rmmissing(T) =
Var1 Var2 Var3
____ ____ ____
38 71 176
38 64 131
49 64 119
  2 件のコメント
Jonathan Beard
Jonathan Beard 2019 年 4 月 26 日
This treats empty and nan equivalently. If you know the column that contains nans for which you want to remove the corresponding rows of you can use something like this.
T = T(find(~isnan(T.ColumnWithSomeNans)), :);
Walter Roberson
Walter Roberson 2019 年 4 月 26 日
Only numeric values can be nan (or not), and numeric values in a table cannot be empty: the table-reading process fills them in with a definite value (typically nan.)
You would need to go back to the original file (if it is text) or use activex or .NET talking to Excel in order to determine whether a location is empty rather than nan.

サインインしてコメントする。

その他の回答 (1 件)

Walter Roberson
Walter Roberson 2018 年 6 月 13 日
T( any(ismissing(T),2), :) = [];
  4 件のコメント
Walter Roberson
Walter Roberson 2018 年 6 月 13 日
rmmissing is good, and I did not know about it. I voted for Paolo's answer, but I left mine as an alternative solution.
Blake
Blake 2019 年 9 月 19 日
Walter thanks:
For some reason, Pablo's answer didn't work on my data which had mixed data types, but yours did.

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by