rmmissing
Removes missing entries (NaN, empty text, undefined) from arrays and tables.
Category: Language Fundamentals > Data Types
Syntax
B = rmmissing(A)
Removes elements of a vector, or the rows of a matrix or table, that contain missing values.
B = rmmissing(A, dim)
Removes along dimension dim; 2 removes columns.
B = rmmissing(___, 'MinNumMissing', n)
Removes only rows or columns that have at least n missing values.
[B, TF] = rmmissing(___)
Also returns a logical index of what was removed.
Description
What counts as missing depends on the type: NaN for numbers, <missing> for strings, empty character vectors in a cell array of text, <undefined> for categorical and NaT for datetime. An empty string "" in a string array is not missing.
By default one missing value is enough to remove a whole row (a column when dim is 2). Raise 'MinNumMissing' to require more.
Input arguments
A- Numeric array, string array, cell array of character vectors, categorical or table.
dim- Dimension to remove along.
Output arguments
B- Array without the missing entries.
TF- Logical column or row vector marking the removed rows or columns.
Example
rmmissing([1 NaN 3 4])
rmmissing([1 NaN; 3 4])
rmmissing([1 NaN; 3 4], 2)
T = table([1;NaN;3], ["a";"b";missing], 'VariableNames', {'A','B'});
[R, TF] = rmmissing(T)
Output
ans = 1×3
1 3 4
ans = 1×2
3 4
ans = 2×1
1
3
R = 1×2 table
A B
_ ___
1 "a"
TF = 3×1 logical array
0
1
1