Okay this is a weird error. I apologize for this confusion.
First, the problem with my for
loop is that this version of DataFrames doesn’t allow String
indexing. You should replace "x$i"
with Symbol(:x, i)
and the code will work.
The second, more confusing error is related to the code
DataFrame(["x$(i)" => getindex.(dfy.a, i) for i in 1:3])
It seems there was a breaking change in the constructor of DataFrames between 0.20.0
and 0.21.0
that I did not know about.
In 0.20.2
we have
julia> DataFrame(["x$(i)" => getindex.(dfy.a, i) for i in 1:3])
3×2 DataFrame
│ Row │ first │ second │
│ │ String │ Array… │
├─────┼────────┼───────────┤
│ 1 │ x1 │ [1, 4, 7] │
│ 2 │ x2 │ [2, 5, 8] │
│ 3 │ x3 │ [3, 6, 9] │
On 0.21.0
we have
julia> DataFrame(["x$(i)" => getindex.(dfy.a, i) for i in 1:3])
3×3 DataFrame
│ Row │ x1 │ x2 │ x3 │
│ │ Int64 │ Int64 │ Int64 │
├─────┼───────┼───────┼───────┤
│ 1 │ 1 │ 2 │ 3 │
│ 2 │ 4 │ 5 │ 6 │
│ 3 │ 7 │ 8 │ 9 │
@bkamins do you know why this constructor changed?
OP, my advice is to update DataFrames and use the examples put forward in this thread.