let d=Dict(:yes => 1, :no => 2, :mixed => 3)
df1[:y] = map(elt->d[elt], df1[:y])
end
On Tue, Jun 21 2016, akrun wrote:
> If the DataFrame is
>
>
> using DataFrames
> srand(2)
> df1 = DataFrame(x=rand(5), y = rand([:yes, :no, :mixed], 5))
>
>
> I can replace an element say 'yes' with 1 using map
>
> df1[:y] = map(e -> replace(string(e), "yes", 2), df1[:y])
> and can do
>
> How do I replace all the elements , 'no' with 2, 'mixed with 3 and 'yes' in
> a single step.
>
> I tried
>
> for j in [:yes, :no, :mixed], i in eachindex(j)
> map(e -> replace(string(e), j, i), df1[:y])
> end
> # ERROR: MethodError: `eachindex` has no method matching
> eachindex(::Symbol)
> #in anonymous at no file