TransformMissing

TransformMissing[tab,spec]

replaces instances of Missing[] in tabular data tab according to the specification spec.

TransformMissing[tab,{col1spec1,}]

uses the specification speci to replace missing elements in coli.

Details and Options

  • TransformMissing is also known as missing handling and missing imputation.
  • TransformMissing is used to replace missing elements in a dataset with values that can be specified or inferred from the known part of the data.
  • Missing value handling is typically used to maintain dataset integrity (often required for further data processing) and to preserve the original dataset sample size.
  • Possible forms of tab include:
  • {assoc1,}a list of associations
    {x11,}a matrix
    Dataset[]a dataset object
    Tabular[]a tabular object
  • Transformation specification spec based on the all the non-missing column values includes:
  • " Mean"the mean value
    "Median"the median value
    "Mode"the most frequent value
  • These methods assume missing data is random (MCAR) and the imputed value reflects a consistent, representative dataset, working best when data lacks skew or outliers.
  • Transformation based on a constant value includes:
  • {"Constant", val}a constant value val
  • Transformation based on sampling includes:
  • "RandomElement"randomly selected value
    {"RandomVariate",dist}value sampled from dist
  • If the distribution dist has free parameters, these will be estimated from the non-missing data using EstimatedDistribution.
  • Transformation based on the element position includes:
  • "NearestElement"use the closest non-missing element
    "NextElement"use the next non-missing element
    "PreviousElement"use the previous non-missing element
  • These methods assume that missing values are similar to nearby data points and are useful for filling small gaps in sequential or time-based data.
  • Transformation based on interpolation includes:
  • "Interpolation"use interpolation
    {"Interpolation",InterpolationOrderdegree}specify the interpolation order degree
  • Interpolation assumes that missing data lies on a smooth, continuous path between known points, making it most effective for datasets with gradual changes and minimal sharp fluctuations.
  • Additional methods can be implemented using TransformColumns and other transformation functions.
  • When specifying the desired columns, coli can have the following formats:
  • nthe nth column
    "name"the column "name"
    TypeSpecifier[]columns matching the specified type
    Allall the columns
    Automaticautomatically find columns based on spec (default)

Examples

open allclose all

Basic Examples  (2)

Replace missing elements by using the mean value of the columns:

Use a literal value:

Fit a distribution on the column data and sample from it:

Scope  (15)

Column Specification  (4)

Transform the specified column:

Transform a list of columns:

Transform all the columns:

Transform the columns that are compatible with the "Mean" transformation:

This is equivalent to:

Transformations  (11)

Constant  (4)

Impute missing values with the mean of a column:

Impute missing values with the median of a column:

Impute missing values with the most common value of a column:

Impute missing values with a constant value:

Random  (2)

Impute each missing value with a random choice from its column:

Sample from a given distribution:

Sample after estimating the distribution on the (non-missing) column values:

Position Based  (3)

Replace missing values using the previous non-missing value:

Replace missing values using the next non-missing value:

Replace missing values using the closest non-missing value:

Interpolation Based  (2)

Impute missing values sampling from an InterpolatingFunction:

Specify an interpolation order:

Possible Issues  (1)

Not all transformations are compatible with every data type:

Wolfram Research (2025), TransformMissing, Wolfram Language function, https://reference.wolfram.com/language/ref/TransformMissing.html.

Text

Wolfram Research (2025), TransformMissing, Wolfram Language function, https://reference.wolfram.com/language/ref/TransformMissing.html.

CMS

Wolfram Language. 2025. "TransformMissing." Wolfram Language & System Documentation Center. Wolfram Research. https://reference.wolfram.com/language/ref/TransformMissing.html.

APA

Wolfram Language. (2025). TransformMissing. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/TransformMissing.html

BibTeX

@misc{reference.wolfram_2024_transformmissing, author="Wolfram Research", title="{TransformMissing}", year="2025", howpublished="\url{https://reference.wolfram.com/language/ref/TransformMissing.html}", note=[Accessed: 15-January-2025 ]}

BibLaTeX

@online{reference.wolfram_2024_transformmissing, organization={Wolfram Research}, title={TransformMissing}, year={2025}, url={https://reference.wolfram.com/language/ref/TransformMissing.html}, note=[Accessed: 15-January-2025 ]}