table

Methods

Method Reference: table.rmmissing

table: tbl = rmmissing (tblA)
table: tbl = rmmissing (…, Name, Value)
table: [tbl, TF] = rmmissing (…)

Remove missing table elements by rows.

tbl = rmmissing (tblA) returns a table with the rows of tblA that contain at least one missing value removed. Missing values are determined per variable according to its data type (NaN for numeric, NaT for datetime, <missing> for string, <undefined> for categorical, {''} for cellstr, etc.), as reported by ismissing.

tbl = rmmissing (…, Name, Value) customizes the operation with the following options:

'MinNumMissing'
A positive integer n (default 1). A row is removed only when it has at least n variables with a missing value.
'DataVariables'
Restrict the search for missing values to the indicated subset of table variables, using the same variable referencing as the other table methods. Variables outside the subset are not inspected, but all variables are kept in the output.
'MissingLocations'
Supply the missing-value locations explicitly instead of deriving them with ismissing. The value is either a logical matrix with one row per row of the input and one column per inspected variable, or a table of logical variables whose names and sizes match the inspected variables.

[tbl, TF] = rmmissing (…) also returns a logical column vector TF, with one element per row of tblA, that is true for each removed row.

Source Code: table

Example: 1

rmmissing drops every row that has a missing value in any variable — listwise deletion — counting gaps of every type (NaN, NaT, <undefined>, <missing>). Here the rows with a missing age, grade, or visit all go.

 Name = string ({'Li'; 'Diaz'; 'Brown'; 'Lee'});
 Age = [38; NaN; 40; 49];
 Grade = categorical ({'A'; 'B'; ''; 'C'});
 Visit = datetime (2024, 1, [5; 6; 7; 8]);
 T = table (Name, Age, Grade, Visit)
T =
  4x4 table

     Name      Age       Grade          Visit       
    _______    ___    ___________    ___________    

    "Li"        38              A    05-Jan-2024    
    "Diaz"     NaN              B    06-Jan-2024    
    "Brown"     40    <undefined>    07-Jan-2024    
    "Lee"       49              C    08-Jan-2024
 rmmissing (T)
ans =
  2x4 table

    Name     Age    Grade       Visit       
    _____    ___    _____    ___________    

    "Li"      38        A    05-Jan-2024    
    "Lee"     49        C    08-Jan-2024

A second output is the logical mask of the rows that were removed.

 [C, removed] = rmmissing (T);
 removed'
ans =

  0  1  1  0