I am trying to write a function that I can use to recode values into a new variable of Int8 type:
function recode!(df::DataFrame, old::Symbol, new::Symbol, coding::Dict)
df[new] = DataArray([isna(x) ? NA : coding[x] for x in df[old]])
end
recode!(df,:race,:race3,Dict(1=>5,2=>6,3=>7,4=>8))
This creates a DataArray of Union{DataArrays.NAtype,Int64} type. Is there an easy way of forcing Int8 type?