Is there a way to create a DataArray of a particular eltype (Int8 in my case) using a list comprehension or a map function?

46 views
Skip to first unread message

Min-Woong Sohn

unread,
Jun 28, 2016, 11:43:14 PM6/28/16
to julia-users
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?


Ken B

unread,
Jun 29, 2016, 5:03:26 AM6/29/16
to julia-users
You could try Int8[ ... ] to get the required type.
Reply all
Reply to author
Forward
0 new messages