Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

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 and duration arrays

  • <undefined> for categorical arrays

  • Empty character vector, {''}, for cell arrays of character vectors

  • Blank character vector, [' '], for character arrays

  • NaT for datetime arrays

ismissing ignores other data types.

example

TF = ismissing(A,id) treats the values in id as missing value indicators. When you specify id, you must include the indicators listed in the previous syntax to have ismissing recognize them as missing value indicators.

Examples

collapse all

Missing Values in Table with Various Data Types

Create a table with variables of different data types and find the elements with missing values.

dblVar = [NaN;3;5;7;9;11];
singleVar = single([1;NaN;5;7;9;11]);
cellstrVar = {'one';'three';'';'seven';'nine';'eleven'};
charVar = ['A';'C';'E';' ';'I';'J'];
categoryVar = categorical({'red';'yellow';'blue';'violet';'';'ultraviolet'});
m = [1:2:10];
dateVar = [datetime(2015,m,15) NaT]';

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

    dblVar    singleVar    cellstrVar    charVar    categoryVar      dateVar  
    ______    _________    __________    _______    ___________    ___________

    NaN         1          'one'         A          red            15-Jan-2015
      3       NaN          'three'       C          yellow         15-Mar-2015
      5         5          ''            E          blue           15-May-2015
      7         7          'seven'                  violet         15-Jul-2015
      9         9          'nine'        I          <undefined>    15-Sep-2015
     11        11          'eleven'      J          ultraviolet    NaT        

ismissing returns 1 where the corresponding element in A has a missing value.

TF = ismissing(A)
TF =

     1     0     0     0     0     0
     0     1     0     0     0     0
     0     0     1     0     0     0
     0     0     0     1     0     0
     0     0     0     0     1     0
     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. Then, find the elements with 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      

ismissing returns 1 where the corresponding element in A has a missing value.

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 each variable of table A as missing values. ismissing ignores trailing white space in character arrays. Therefore, since the empty character vector, '', is specified as a missing value indicator, ismissing identifies as missing values the empty character vector in A.cellstrVar, and also the blank space in A.charVar.

Input Arguments

collapse all

A — Input datatable

Input data, specified as a table.

id — Missing value indicatorsnumeric vector | character vector | cell array containing numeric values and character vectors

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

When you specify id, you must include NaN, the empty character vector, '<undefined>', or NaT to have ismissing recognize these values as missing value indicators.

When you specify the empty character vector as a missing value, ismissing treats empty character vectors in cell arrays of character vectors, and also blank character vectors in character arrays, as missing values.

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

Data Types: double | char | cell

More About

collapse all

Tips

  • To return only complete rows from A, use A(~any(TF,2),:).

  • To return only the variables from A with no missing values, use A(:,~any(TF,1)).

  • Since integer variables cannot store NaN, 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 character vectors, character arrays, and categorical arrays.

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

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

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

Introduced in R2013b

Was this topic helpful?