standardizeMissing
Replaces chosen placeholder values by the standard missing value of the data type.
Category: Language Fundamentals > Data Types
Syntax
B = standardizeMissing(A, indicator)
Returns a copy of A in which every element equal to indicator becomes missing.
Description
Datasets often use a sentinel such as -99 or 'N/A' where a value is absent. standardizeMissing turns those sentinels into the native missing value, so functions such as ismissing, rmmissing, fillmissing and the 'omitnan' options treat them correctly.
The replacement depends on the type: NaN for floating point data, <missing> for strings, and an undefined entry for categorical data. Integer arrays have no missing value, so they are returned unchanged.
Input arguments
A- Numeric array, string array, cell array of character vectors, categorical array, or a table.
indicator- The value (or list of values, as a vector or cell array) that marks missing data in
A.
Output arguments
B- Array of the same size and class as
A, with the indicated elements replaced byNaN,<missing>or the equivalent for the type.
Example
Numeric and string placeholders
A = [1 -99 3 -99 5];
B = standardizeMissing(A, -99)
standardizeMissing(["a" "N/A"], "N/A")
Output
B = 1×5
1 NaN 3 NaN 5
ans = 1×2 string array
"a" <missing>