I have a DataFrame
dfy = DataFrame(a = [[1,2,3],[4,5,6],[7,8,9]], b = [“M”,“F”,“F”])
3×2 DataFrame
│ Row │ a │ b │
│ │ Array… │ String │
├─────┼───────────┼────────┤
│ 1 │ [1, 2, 3] │ M │
│ 2 │ [4, 5, 6] │ F │
│ 3 │ [7, 8, 9] │ F │
I would like to append new variable x1 based on first column from dfy.a, x2 based on second column from dfy.b, and x3 based on third column fron dfy.b.
3×5 DataFrame
│ Row │ a │ b │ x1 │ x2 │ x3 │
│ │ Array… │ String │ Int64 │ Int64 │ Int64 │
├─────┼───────────┼────────┼───────┼───────┼───────┤
│ 1 │ [1, 2, 3] │ M │ 1 │ 2 │ 3 │
│ 2 │ [4, 5, 6] │ F │ 4 │ 5 │ 6 │
│ 3 │ [7, 8, 9] │ F │ 7 │ 8 │ 9 │
Short of doing the below, is there a way I can use for loop or some other way to create the above dataset?
dfy[!,:x1]= getindex.(dfy.a,1)
dfy[!,:x2]= getindex.(dfy.a,2)
dfy[!,:x3]= getindex.(dfy.a,3)