How to delete rows that contain NaN in a table

150 次查看(过去 30 天)
Hello all,
So how do you delete all the rows that contain NaNs in a table (not a matrix or a cell array)? I have tried various versions of
tableA(~any(~isnan(tableA), 2),:)=[];
but none work.
Thank you
  1 个评论
Image Analyst
Image Analyst 2017-2-3
Make it easy for us to help you by suppling code to generate a table with nans in it. Then I can try some things. And do any of your columns contain anything other than numbers? Like strings or something?

请先登录,再进行评论。

采纳的回答

dpb
dpb 2017-2-3
编辑:dpb 2017-6-12
If the table uses default missing values for the various types (see documentation for the various types; NaN is for numeric) then
tableA=tableA(~any(ismissing(tableA),2),:);
should do the trick. This will eliminate other variables that are missing besides numeric, too, of course, leaving only a complete table.
  2 个评论
sensation
sensation 2017-6-12
Hi,
I have tried this but got an error: Error using any Not enough input arguments.
I have first column as string and second is numeric with nan values sometimes inside. I want to get riw of those rows with nans.
thank you
dpb
dpb 2017-6-12
Missing parens... ismissing(tableA) returns 2D logical, need any applied to it in 2d dimension to return the rows with missing value, then keep the complement.

请先登录,再进行评论。

更多回答(1 个)

Peter Perkins
Peter Perkins 2017-2-6
If you have access to R2016b, you can use rmmissing .

类别

Help CenterFile Exchange 中查找有关 Tables 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by