Can't get all the rows in my table that have any missing values and remove those rows
Afficher commentaires plus anciens
Hi there,
I am trying to remove my table (of a combination of double, cell arrays and duration arrays) of any rows which have missing values. For example, a subset of the table is:
'' '' '441' '0'
'' '' '5' '0'
'No' '' '2889' '0'
'No' 'Clicks' '2894' '0'
'' '' '' '0'
'' '' '5' '0'
'No' 'ROD' '3591' '1'
'' '' '' '0'
My code is:
badRows = ismissing(finalnbs);
T = finalnbs(~badRows, :);
However, this results in an error:
Row index exceeds table dimensions.
What am I doing wrong, and what code do I need to achieve my need?
4 commentaires
the cyclist
le 18 Déc 2015
Could you upload one of the following?
- A *.mat file with the actual table
- Code that reproduces the table, or at least a subset of it that recreates the problem
Image Analyst
le 18 Déc 2015
Yes, it's always a good idea for posters to give complete code that we can copy and paste, not like what you did. So, my question is how can you have 5 or more missing values in a row when the rows of your table have only 4 columns?
Guillaume
le 18 Déc 2015
Also, don't put questions in the title, particularly if it is a different question than in the body.
Both the cyclist and I answer your question in the body (remove any row which has missing value). The answer to remove any row that has more than x missing values is completely different
Dhruv Ghulati
le 18 Déc 2015
Réponse acceptée
Plus de réponses (1)
badRows is an m*n logical array, where m is the number of rows and n the number of columns of your table. So it has m*n elements. You're then using that as a row index into your table, so of course, matlab can't fit m*n values into m values.
T = finalnbs(~any(badrows, 2), :);
%or
T = finalnbs(all(~badrows, 2), :);
P.S.: this answer your question on how to remove any row which has missing value. If you want to remove rows have more than x missing values, then you use sum instead:
T = finalnbs(sum(badrows, 2) <= x, :);
Catégories
En savoir plus sur Tables dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!