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 and duration,
'' for cell arrays of character vectors, <missing> for
string, <undefined> for categorical, and
NaT for datetime).
indicator may be a numeric scalar or vector, a character vector, a
string array, a cell array of character vectors, a
duration or datetime array, or a cell array mixing any of
these. Each indicator is applied only to the variables whose type is
compatible with it: numeric indicators match double and
single variables, text indicators (char, string, or
cellstr) match cell-array-of-character-vector, string, and
categorical variables, duration indicators match
duration variables, and datetime indicators match
datetime variables. A datetime indicator matches the same
instant in any time zone, but indicators with and without a time zone
cannot be mixed, nor compared with a variable that differs from them in
having one.
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
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