SkipNan

Documentation for SkipNan.

About

Use skipnan as you would use skipmissing.

Installation

SkipNan can be installed from the Julia package registry via:

using Pkg
Pkg.add("SkipNan")

Use

julia> using SkipNan
julia> x = skipnan([1., NaN, 2.])skipnan([1.0, NaN, 2.0])
julia> sum(x)3.0
julia> collect(x)2-element Vector{Float64}: 1.0 2.0
julia> collect(keys(x))2-element Vector{Int64}: 1 3
julia> x[1]1.0
julia> x[3]2.0
julia> x[2]ERROR: MissingException: the value at index (2,) is missing

Reference

SkipNan.skipnanMethod
skipnan(itr)

Return an iterator over the elements in itr skipping NaN values, analogous to skipmissing. The returned object can be indexed using indices of itr if the latter is indexable. Indices corresponding to missing values are not valid: they are skipped by keys and eachindex, and a MissingException is thrown when trying to use them. Use collect to obtain an Array containing the non-missing values in itr. Note that even if itr is a multidimensional array, the result will always be a Vector since it is not possible to remove NaNs while preserving dimensions of the input.

Examples

julia> x = skipnan([1., NaN, 2.])
skipnan([1.0, NaN, 2.0])
julia> sum(x)
3.0
julia> x[1]
1.0
julia> x[2]
ERROR: MissingException: the value at index (2,) is missing
[...]
julia> argmax(x)
3
julia> collect(keys(x))
2-element Vector{Int64}:
 1
 3
julia> collect(skipnan([1., NaN, 2.]))
2-element Vector{Float64}:
 1.0
 2.0
julia> collect(skipnan([1. NaN; 2. NaN]))
2-element Vector{Float64}:
 1.0
 2.0
source