Why are missing values not ignored by default?

I see.

Is it possible that Statistics implements either (both) of the naive algorithms, but not something more numerically stable, such as

function avg(x)
    a = zero(eltype(x))
    for i in eachindex(x)
        a += (x[i] - a) / i;
    end
    return a
end 

?

julia> x = rand(Float16, 10^6);

julia> mean(x)
NaN

julia> avg(x)
4.92920e-01

2 Likes