pretty simple question with no documentation that I could find. is this the right way to get a 3x1 array of missings that at some point I may want to fill with with Int?
julia> x = Union{Int64, Missings.Missing}[missing for i in 1:3]
3-element Array{Union{Int64, Missings.Missing},1}:
missing
missing
missing
julia> x[2] = 1
1
the other way I could think is a bit contrived, given that I would like to initiate to missing
julia> x=Vector{Union{Int64, Missings.Missing}}(3)
3-element Array{Union{Int64, Missings.Missing},1}:
#undef
#undef
#undef
julia> x[2] = 1
1
julia> x[1] = missing
missing
julia> x
3-element Array{Union{Int64, Missings.Missing},1}:
missing
1
#undef
cheers
julia> Vector{Union{Int,Missing}}(missing, 3)
3-element Array{Union{Missing, Int64},1}:
missing
missing
missing
Perhaps
convert(Array{Union{Missing, Int}}, fill(missing, 3, 1))
or
fill!(Array{Union{Missing, Int}}(3, 1), missing)
but it is not much better. I wish fill would take a type argument.
piever
January 30, 2018, 3:29pm
4
Either
using Missings
missings(Int64, 10)
or:
using DataArrays
DataArray(Int64, 10)
if you want a DataArray
How about
missings(Int64, 3)
This should work for any type.
i like that most, thanks! had no idea how to use the Missings.jl package.
A related question, will Missing in a DataFrame, produce an empty box?
nilshg
October 1, 2021, 7:53am
9
What does “empty box” mean? Also I don’t really see how the question is connected, better to start a new thread than to post in a 4-year old one.
A box that contains no value. Maybe it should be it’s own topic.
Leaving the “box” aside, why wasn’t the quoted answer accepted as the more Julian solution? Thank you.
It would be nice to see
missings([T=Float64,] dims::Tuple)
added to Base