Dear J wizard—I want to code my own basic recode
(without CategoricalArrays, which has very deep dependencies, via DataStream into … ). easy me thinks.
julia> recode( v::Vector, p::Pair )= ( T= Vector{Union{typeof(p[1]),typeof(p[2])}}; v=T(v); ifelse.( isequal.(v,p[1]) , p[2], v ))
recode (generic function with 1 method)
and now
julia> recode( [1.0,2.0,3.0], 2.0 => NaN ) . ## perfect
3-element Array{Float64,1}:
1.0
NaN
3.0
julia> using Missings
julia> recode( [1.0,2.0,3.0], 2.0 => missing ) . ## not so perfect.
3-element Array{Any,1}:
1.0
missing
3.0
how do I get the Any to be the Union?