Insert missing/nan elements in BitMatrix

In Julia 1.6, I create a boolean array

x= trues(3,2)

and I want to reflect that an element is missing (or nan if it is compatible). I tried the following but they return errors

x[2,2] = missing
x[2,2] = NaN

Is there a way to do that?

x= convert(Matrix{Any}, trues(3,2))

(if you just need missing I may recommend Matrix{Union{Bool, Missing}})

1 Like

A BitMatrix can only store bits, so you need to convert your data to a type capable of holding missing values.

julia> x = convert(Matrix{Union{Missing, Bool}}, x)
3×2 Matrix{Union{Missing, Bool}}:
 true  true
 true  true
 true  true

julia> x[2, 2] = missing
missing

julia> x
3×2 Matrix{Union{Missing, Bool}}:
 true  true
 true      missing
 true  true
4 Likes