Skip to content

Mean of an array with missing values does not work if the dims argument is provided #7

@oxinabox

Description

@oxinabox
julia> using Statistics

julia> x = [(i==3 && j==3) ? missing : i*j for i in 1:3, j in 1:4]
3×4 Array{Union{Missing, Int64},2}:
 1  2  3          4
 2  4  6          8
 3  6   missing  12

julia> mean(x)
missing

julia> mean(x; dims=1)
ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type Float64
    # SNIP 
julia> mean(x; dims=2)
ERROR: MethodError: Cannot `convert` an object of type Missing to an object of type Float64
    # SNIP

Expected is:

julia> mean(x; dims=1)
1×4 Array{Union{Missing,Float64},2}:
 2.0  4.0  missing  8.0

julia> mean(x; dims=2)
3×1 Array{Union{Missing,Float64},2}:
 2.5
 5.0
 missing

(credit to @nickrobinson251 who found this)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions