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 missing values

Syntax

Description

example

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

Indicators for missing data depend on the data type:

  • NaN for double, single, duration, and calendarDuration

  • NaT for datetime

  • <missing> for string

  • <undefined> for categorical

  • ' ' for char

  • {''} for cell of character arrays

example

TF = ismissing(A,indicator) treats the values in indicator as missing value indicators, ignoring all default indicators listed in the previous syntax.

Examples

collapse all

Create a row vector A that contains NaN values, and identify their location in A.

A = [3 NaN 5 6 7 NaN NaN 9];
TF = ismissing(A)
TF =

  1×8 logical array

   0   1   0   0   0   1   1   0

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 =

  6×6 logical array

   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.

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 =

  5×4 logical array

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

ismissing ignores trailing white space in character arrays. Therefore, since the empty character vector, '', is specified as a missing value indicator, ismissing identifies the empty character vector in A.cellstrVar and also the blank space in A.charVar as missing values.

Input Arguments

collapse all

Input data, specified as a vector, matrix, multidimensional array, table, or timetable. If A is a timetable, then ismissing operates on the table data only and ignores NaT and NaN values in the vector of row times.

Data Types: double | single | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | cell | table | timetable | categorical | datetime | duration | calendarDuration

Missing value indicators, specified as a vector or cell array. The entries of indicator indicate the values that ismissing treats as missing. Specifying indicator overrides all default missing indicators. When A contains multiple data types and you want to designate indicator for only one of them, you must include all other default indicators as elements of indicator in order for ismissing to recognize them. For example, if A is a table with categorical and numeric values, use ismissing(A,{-99,'<undefined>'}) to indicate -99 as a missing numeric value, but preserve <undefined> as a missing categorical value.

Indicator data types match data types in the corresponding entries of A. The following are additional data type matches between the indicator and elements of A:

  • double indicators match double, single, integer, and logical entries of A.

  • string and char indicators match categorical entries of A.

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

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | cell | datetime | duration

More About

collapse all

Tall Array Support

This function fully supports tall arrays. For more information, see Tall Arrays.

Tips

  • Since integer variables cannot store NaN, use a special integer value (otherwise unused) to indicate missing integer data, such as -99.

Algorithms

ismissing handles 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.

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

Introduced in R2013b

Was this topic helpful?