Is there a function available to check in a large vector, if one of the following occurs in a vector:
- missing
- nothing
- Inf
- NaN
?
Here is my snippet to investigate a vector for such elements:
a = [1.3, NaN, Inf, missing, nothing, 1.3]
# ---
println('-'^100)
for i_element in a
if isa(i_element, Number)
println("is number: ", i_element," ,\t isnan(i_element): ", isnan(i_element), ", \t isinf(i_element)", isinf(i_element))
else
println("is no number: ", i_element)
end
end
println('-'^100)
# --- find non-number plus Inf plus NaN elements: -----------------------------------------
vector_ = isa.(a, Number)
b = a[vector_]
c = isinf.(b) .| isnan.(b)
b_contains_bad_elements = any(c)
if b_contains_bad_elements
println("vector \"a\" contains bad elements")
end
# --- local function: -----------------------------------------------------------------------------------
function _contains_bad_elements(_vec::AbstractVector)
_isnumber = isa.(_vec, Number)
_nonumber = false .== _isnumber
_numbers = _vec[_isnumber]
return any(vcat(isinf.(_numbers) .| isnan.(_numbers), _nonumber))
end
# ---
_isusefulnumber(a)