Reputation: 2902
The Statistics package mean
function returns missing
if any elements of an array
are missing.
julia> using Statistics
julia> mean([1 2 3 4 5] )
3.0
julia> mean([1 2 missing 4 5] ) # Note missing value
missing
How do I get the mean of the non-missing values?
Upvotes: 5
Views: 3708
Reputation: 2902
The skipmissing
function will send only the non-missing elements to the mean
function:
julia> using Statistics
julia> mean([1 2 3 4 5] )
3.0https://docs.julialang.org/en/stable/manual/missing/#Skipping-Missing-Values-1
julia> mean([1 2 missing 4 5] ) # Note missing value
missing
# Here is the answer:
julia> mean(skipmissing([1 2 missing 4 missing] ))
2.3333333333333335
As pointed out by @Milan Bouchet-Valat in a comment to the question, the docs on missing
are here. They are a good quick, first read on Julia's handling of missing values.
Upvotes: 6