ismissing

Find table elements with missing values

Syntax

Description

example

TF = ismissing(A) returns a logical array, TF, that indicates which elements in the table A contain a missing value. The size of TF is the same as the size of A.

Indicators for missing data depend on the data type:

  • NaN for numeric arrays

  • <undefined> for categorical arrays

  • empty string, {''}, for cell arrays of strings

  • blank string, [' '], for character arrays

ismissing ignores other data types.

example

TF = ismissing(A,id) treats the values in id as missing value indicators. You must include NaN (for floating-point variables), the empty string (for variables that are cell arrays of strings or character arrays), or the string '<undefined>' (for categorical variables) to have ismissing recognize them as missing value indicators.

Examples

expand all

Missing Values in Table with Various Data Types

Create a table with variables of different data types where each contains a missing value.

dblVar = [NaN;3;5;7;9];
singleVar = single([1;NaN;5;7;9]);
cellstrVar = {'one';'three';'';'seven';'nine'};
charVar = ['A';'C';'E';' ';'I'];
categoryVar = categorical({'red';'yellow';'blue';'violet';''});

A = table(dblVar,singleVar,cellstrVar,charVar,categoryVar)
A = 

    dblVar    singleVar    cellstrVar    charVar    categoryVar
    ______    _________    __________    _______    ___________

    NaN         1          'one'         A          red        
      3       NaN          'three'       C          yellow     
      5         5          ''            E          blue       
      7         7          'seven'                  violet     
      9         9          'nine'        I          <undefined>

Find the table elements with missing values.

TF = ismissing(A)
TF =

     1     0     0     0     0
     0     1     0     0     0
     0     0     1     0     0
     0     0     0     1     0
     0     0     0     0     1

The size of TF is the same as the size of A.

Specify Indicators for Missing Values in Table

Create a table where 'NA', ''-99, NaN, and Inf represent missing values.

dblVar = [NaN;3;Inf;7;9];
int8Var = int8([1;3;5;7;-99]);
cellstrVar = {'one';'three';'';'NA';'nine'};
charVar = ['A';'C';'E';' ';'I'];

A = table(dblVar,int8Var,cellstrVar,charVar)
A = 

    dblVar    int8Var    cellstrVar    charVar
    ______    _______    __________    _______

    NaN         1        'one'         A      
      3         3        'three'       C      
    Inf         5        ''            E      
      7         7        'NA'                 
      9       -99        'nine'        I      

Find the missing values in the table A.

id = {'NA' '' -99 NaN Inf};
TF = ismissing(A,id)
TF =

     1     0     0     0
     0     0     0     0
     1     0     1     0
     0     0     1     1
     0     1     0     0

ismissing recognizes data in the each variable of the table, A as missing values. ismissing ignores trailing white space in character arrays. Therefore, since the empty string, '', is specified as a missing value indicator, ismissing identifies the empty string in the cell arrays of strings, A.cellstrVar, as well as the blank space in character array, A.charVar as missing values.

Input Arguments

expand all

A — Input tabletable

Input table, specified as a table.

id — Missing value indicatorsnumeric vector | string | cell array containing numeric values and strings

Missing value indicators, specified as a numeric vector, string, or cell array containing numeric values and strings. Use strings to identify categories in categorical variables that you want to treat as missing values.

You must include NaN (for floating-point variables), the empty string (for variables that are cell arrays of strings or character arrays), or the string '<undefined>' (for categorical variables) to have ismissing recognize them as missing value indicators.

Example: TF = ismissing(A,-99) recognizes only -99 as a missing value.

Data Types: double | char | cell

More About

expand all

Tips

  • You can use A(~any(TF,2),:) to return only complete rows from A and A(:,~any(TF,1)) to return only the variables from A with no missing values.

  • Integer variables cannot store NaN; therefore, you must use a special integer value (otherwise unused) to indicate missing integer data. For example, -99.

Algorithms

ismissing treats leading and trailing white space differently for cell arrays of strings, character arrays, and categorical arrays.

  • For cell arrays of strings, ismissing does not ignore white space. All strings must match exactly.

  • For character arrays, ismissing ignores trailing white space. Therefore, when you specify the empty string, '', as a missing value indicator, ismissing identifies the empty string in cell arrays of strings, '', and the blank space in character arrays, ' ', as missing values.

  • For categorical arrays, ismissing ignores leading and trailing white space.

Was this topic helpful?