liveBook · Manning

Missing value

As explained in Julia as a Second Language

Missing data is information absent from a collected dataset because it was not recorded, was lost, or is otherwise unavailable.

A missing value represents data that exists in the real world but was not recorded, was lost, or is otherwise unknown. Julia represents it with the missing object, whose type is Missing. This differs from nothing: nothing means that something does not exist, while missing means that its value is unavailable. section 10.3 section 10.6

Missing values propagate through calculations instead of immediately throwing an exception. For example, 10 + missing evaluates to missing, warning that the result cannot be known. This behavior helps expose unnoticed gaps in statistical or scientific data. section 10.3

Summarizing incomplete data

Given xs = [2, missing, 4, 8], sum(xs) returns missing because the input is incomplete. To calculate over the known values, use sum(skipmissing(xs)), which returns 14; mean(skipmissing(xs)) and median(skipmissing(xs)) similarly exclude the missing entry. section 10.3

Keep these unknown-value cases separate:

  • Use missing for unavailable input data, such as an unanswered survey field or an incomplete experiment. section 10.7
  • Use nothing when a result or object does not exist, such as a failed search result. section 10.0 section 10.6
  • Treat NaN as the result of an illegal mathematical operation and undefined as an uninitialized variable, not as missing data. section 10.6 section 10.7
Listing 10.4 Comparing behavior of missing and nothing in mathematical expressions
julia> missing < 10
missing

julia> nothing < 10
ERROR: MethodError: no method matching isless(::Nothing, ::Int64)

julia> 10 + missing
missing

julia> 10 + nothing
ERROR: MethodError: no method matching +(::Int64, ::Nothing)

Compare how missing propagates through comparisons and arithmetic while nothing produces method errors. section 10.3

julia> using Statistics
 
julia> xs = [2, missing, 4, 8];
 
julia> sum(xs)                 #1
missing

julia> sum(skipmissing(xs))    #2
14
 
julia> median(skipmissing(xs))
4.0
 
julia> mean(skipmissing(xs))
4.666666666666667

Run compact Julia examples showing how skipmissing supports sums, medians, and means over incomplete arrays. section 10.3

How Julia as a Second Language covers it

How deep it goes
Explains Missing, propagation, skipmissing, and contrasts with nothing, NaN, and undefined.
Examples
Demonstrates incomplete surveys, unfinished studies, data-entry errors, and arrays processed with skipmissing.
What it assumes
Assumes basic Julia expressions and arrays while distinguishing data absence from programmer-level null and initialization states.
What you can do after
Apply it via Julia’s missing and skipmissing constructs to represent and summarize incomplete data.
How it connects
Connects Missing with nothing, NaN, undefined values, type unions, and statistical aggregation.

Also explained in

Compare how 35 books explain missing value →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Julia as a Second Language. The section links point to the parts of the book it draws on.