table.standardizeMissing
table: tblB = standardizeMissing (tblA, indicator)
table: tblB = standardizeMissing (…, Name, Value)
Insert standard missing values into a table.
tblB = standardizeMissing (tblA, indicator)
replaces every entry of tblA that matches a value in
indicator with the standard missing value of that variable’s data
type (NaN for double/single, '' for cell
arrays of character vectors, <missing> for string, and
<undefined> for categorical).
indicator may be a numeric scalar or vector, a character vector, a
string array, a cell array of character vectors, or a cell array
mixing numeric and text indicators. Each indicator is applied only to
the variables whose type is compatible with it: numeric indicators match
double and single variables, while text indicators (char,
string, or cellstr) match cell-array-of-character-vector,
string, and categorical variables.
The 'DataVariables' Name/Value pair restricts the
operation to a subset of variables, using the same variable referencing
as the other table methods. Variables not selected pass through
unchanged.
Logical and integer variables (which have no standard missing value) and
duration, datetime, and calendarDuration variables
pass through unchanged.
Source Code: table
standardizeMissing turns your own sentinel codes into the standard missing value for each type (NaN here), so later ismissing/rmmissing/ fillmissing calls recognise them. This dataset uses -99 for "no data".
T = table ([38; -99; 40], [71; 69; -99], 'VariableNames', {'Age', 'Height'})
T =
3x2 table
Age Height
___ ______
38 71
-99 69
40 -99
S = standardizeMissing (T, -99)
S =
3x2 table
Age Height
___ ______
38 71
NaN 69
40 NaN
The sentinels are now genuine missing values, ready to be filled or dropped.
rmmissing (S)
ans =
1x2 table
Age Height
___ ______
38 71