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 pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

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','.');

See Also

|