Array and Table not updating in a loop

Hello, I am getting some strange behaviour in a loop which is reading some columns from a table and converting it to an array. The loop seems to exit after the first iteration. I have given a simple example below. If I check the table Subset and the array ArrayX they show values for the when i.Scenario == 1,whereas I would have expected it show values of either the last iteration i.e. i.Scenario == 2 or for all iterations.

Am I missing anything? Is there a way to update the values in the table and array?

using JuliaDB
using Tables
DataT = table([1,1,1,1,1,2,2,2], [1,2,3,4,5,1,2,3], [10,15,100,115,101,10,15,100],[210,215,1200,1215,101,210,215,1200],[310,415,3100,1315,101,310,415,3100],[410,15,4100,4115,1401,410,15,410],[510,515,1500,5115,5101,510,515,1500]; names = [:Scenario, :ID, :T1, :T2, :T3, :T4, :T5])
for k = 1:2
    Subset = select(filter(i -> (i.Scenario == k), DataT), All(Between(:T1, :T5)))
    ArrayX = Tables.matrix(Subset)
    end
using JuliaDB
using Tables
DataT = table([1,1,1,1,1,2,2,2], [1,2,3,4,5,1,2,3], [10,15,100,115,101,10,15,100],[210,215,1200,1215,101,210,215,1200],[310,415,3100,1315,101,310,415,3100],[410,15,4100,4115,1401,410,15,410],[510,515,1500,5115,5101,510,515,1500]; names = [:Scenario, :ID, :T1, :T2, :T3, :T4, :T5])
for k = 1:2
    global Subset = select(filter(i -> (i.Scenario == k), DataT), All(Between(:T1, :T5)))
    global ArrayX = Tables.matrix(Subset)
end

On 1.3.1 at least, not having the “global” declaration makes the variables local to the for loop…

Thank you @pixel27

I have just a simple related question. How can I keep memory of all runs, i.e. table Subset and ArrayX for both k = 1 and 2?

If I set ArrayX[k,:,:] it throws up the error below and I am not sure how I can set something for the table Subset.

using JuliaDB
using Tables
DataT = table([1,1,1,1,1,2,2,2], [1,2,3,4,5,1,2,3], [10,15,100,115,101,10,15,100],[210,215,1200,1215,101,210,215,1200],[310,415,3100,1315,101,310,415,3100],[410,15,4100,4115,1401,410,15,410],[510,515,1500,5115,5101,510,515,1500]; names = [:Scenario, :ID, :T1, :T2, :T3, :T4, :T5])
for k = 1:2
    global Subset = select(filter(i -> (i.Scenario == k), DataT), All(Between(:T1, :T5)))
    global ArrayX[k,:,:] = Tables.matrix(Subset)
end

error DimensionMismatch("tried to assign 3×5 array to 1×5×5 destination")

using JuliaDB
using Tables
DataT = table([1,1,1,1,1,2,2,2], [1,2,3,4,5,1,2,3], [10,15,100,115,101,10,15,100],[210,215,1200,1215,101,210,215,1200],[310,415,3100,1315,101,310,415,3100],[410,15,4100,4115,1401,410,15,410],[510,515,1500,5115,5101,510,515,1500]; names = [:Scenario, :ID, :T1, :T2, :T3, :T4, :T5])
Subsets = []
ArrayXs = []
for k = 1:2
    Subset = select(filter(i -> (i.Scenario == k), DataT), All(Between(:T1, :T5)))
    ArrayX = Tables.matrix(Subset)
    push!(Subsets, Subset)
    push!(ArrayXs, ArrayX)
end

Would be the easiest way…If you wanted to use types then:

ArrayXs = Vector{Array{64,2}}()
Subsets = Vector{IndexedTable}()

Although for Subsets that’s not the exact type…that appears to be IndexedTable{StructArrays.StructArray{NamedTuple{(:T1, :T2, :T3, :T4, :T5),NTuple{5,Int64}},1,NamedTuple{(:T1, :T2, :T3, :T4, :T5),NTuple{5,Array{Int64,1}}},Int64}} which is a little long…

Thanks