Main Content

replaceWithMissing

Class: dataset

(Not Recommended) Insert missing data indicators into a dataset array

The dataset data type is not recommended. To work with heterogeneous data, use the MATLAB® table data type instead. See MATLAB table documentation for more information.

Syntax

ds2 = replaceWithMissing(ds,Name,Value)

Description

ds2 = replaceWithMissing(ds,Name,Value) replaces specified values in a dataset array with standard missing data indicators using options specified by one or more Name,Value pair arguments. Use replaceWithMissing to specify:

  • Which numeric missing value indicators to replace with NaN.

  • Which character missing value indicators to replace with ''.

  • Which categorical levels to replace with <undefined>.

Input Arguments

ds

dataset array.

Name-Value Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

NumericValues

Vector of numeric values that replaceWithMissing replaces with NaN.

CategoricalLevels

Character vector or cell array of character vectors naming the categorical levels that replaceWithMissing replaces with <undefined>.

Strings

Character vector or cell array of character vectors containing the text that replaceWithMissing replaces with ''.

DataVars

Specified set of variables in ds for which replaceWithMissing replaces values. You can specify a positive integer or vector of positive integers indicating the variable column numbers, a variable name or a cell array of variables names, or a logical vector indicating which variables to replace missing values in.

Default: All variables in ds.

Output Arguments

ds2

dataset array that has the specified missing value indicators, in the specified variables of ds, replaced with standard missing value indicators.

Examples

expand all

Replace nonstandard missing value indicators with standard missing value indicators.

Replace numeric missing values coded 99 with NaN, and character missing values coded '.' with ''.

ds = replaceWithMissing(ds,'NumericValues',99,'Strings','.');