Julia Notes5 - Missing Values

Missing values are represented via the missing object, which is the singleton instance of the type Missing.

Propagation

定义methods的时候支持。

Equality and Comparison Operators

propagaton

ismissing(x)

julia> missing == missing
missing

isequal===可以比较missing

The isless operator is another exception: missing is considered as greater than any other value. This operator is used by sort, which therefore places missing values after all other values.>

Logical operators

可以判断出结果则忽略missing。

Control Flow和&& ||

missing不能用作condition.

Array

This kind of array uses an efficient memory storage equivalent to an Array{T} holding the actual values combined with an Array{UInt8} indicating the type of the entry (i.e. whether it is Missing or T).

An array allowing for missing values but which does not contain any such value can be converted back to an array which does not allow for missing values using convert. If the array contains missing values, a MethodError is thrown during conversion

Skipping Missing Values

julia> sum(skipmissing([1, missing]))
1

julia> x = skipmissing([3, missing, 2, 1])
skipmissing(Union{Missing, Int64}[3, missing, 2, 1])

julia> maximum(x)
3

julia> x[1]
3

julia> x[2]
ERROR: MissingException: the value at index (2,) is missing
[...]

julia> findall(==(1), x)
1-element Array{Int64,1}:
 4

julia> findfirst(!iszero, x)
1

julia> argmax(x)
1

julia> collect(x)
3-element Array{Int64,1}:
 3
 2
 1

`

Logical Operations on Arrays

three-valued logic

julia> [1, missing] == [2, missing]
false

julia> [1, missing] == [1, missing]
missing

julia> [1, 2, missing] == [1, missing, 2]
missing

julia> isequal([1, missing], [1, missing])
true

julia> isequal([1, 2, missing], [1, missing, 2])
false

julia> all([true, missing])
missing

julia> all([false, missing])
false

julia> any([true, missing])
true

julia> any([false, missing])
missing