table.rmmissing
table: tbl = rmmissing (tblA)
table: tbl = rmmissing (tblA, dim)
table: tbl = rmmissing (…, Name, Value)
table: [tbl, TF] = rmmissing (…)
Remove missing table elements by rows or by variables.
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. A
variable with several columns counts once in a row where any of its
columns is missing.
tbl = rmmissing (tblA, dim) removes rows when
dim is 1, the default, and variables when dim is 2. With
dim equal to 2, a variable is removed when it holds a missing
value, and the options below count down each variable instead of
across each row.
tbl = rmmissing (…, Name, Value)
customizes the operation with the following options:
'MinNumMissing'1). A row is removed only
when it has at least n variables with a missing value, and with
dim equal to 2 a variable only when it is missing in at least
n rows.'DataVariables'table
methods. Variables outside the subset are not inspected, so they are
kept in the output whatever they hold.'MissingLocations'ismissing; the values the table holds are then not
consulted. The value is either a logical matrix with one row per row of
the input and one column per variable of tblA or per inspected
variable, or a table of logical variables whose names and sizes
match the inspected variables. Where both sizes agree, the columns are
taken in the order of the variables of tblA. [tbl, TF] = rmmissing (…) also returns a logical
vector TF that is true for each removed row, a column with
one element per row of tblA, or with dim equal to 2 for each
removed variable, a row with one element per variable of tblA.
Source Code: table
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