How to delete rows that contain NaN in a table

22 visualizaciones (últimos 30 días)
012786534
012786534 el 3 de Feb. de 2017
Comentada: dpb el 12 de Jun. de 2017
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 comentario
Image Analyst
Image Analyst el 3 de Feb. de 2017
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?

Iniciar sesión para comentar.

Respuesta aceptada

dpb
dpb el 3 de Feb. de 2017
Editada: dpb el 12 de Jun. de 2017
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 comentarios
sensation
sensation el 12 de Jun. de 2017
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 el 12 de Jun. de 2017
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.

Iniciar sesión para comentar.

Más respuestas (1)

Peter Perkins
Peter Perkins el 6 de Feb. de 2017
If you have access to R2016b, you can use rmmissing .

Categorías

Más información sobre Tables en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by