Statistics.jl
Statistics.jl copied to clipboard
InexactError when dealing with means of integers with missings
a = [missing missing; 0 1]
mean(a;dims=2) # InexactError
The answer should be [missing, 0.5].
Note that
a = [missing missing; 1 1]
means(a;dims=2) # [missing 1]
works.
Works with floats. I would guess some call to similar that isnt correct.
julia> b = [missing missing; 0.0 1.0]
2×2 Matrix{Union{Missing, Float64}}:
missing missing
0.0 1.0
julia> mean(b, dims = 2)
2×1 Matrix{Union{Missing, Float64}}:
missing
0.5
Error is this line
julia> Statistics._mean_promote(missing, 1)
1
julia> 1/1
1.0
julia> missing / 1
missing
The solution is probably to add more f(x) / 1 checks to get the output type right, since missing / 1 is not informative of what the output should be the same way 1/1 is. We could also add a skipmissing or something, though that is likely quite costly.
See also https://github.com/JuliaStats/Statistics.jl/issues/7.