Search code examples
dataframefor-loopjuliaglobal-variables

How to make an array from for loop globally available in Julia?


I am writing a code in Julia. Here, I have a dataframe of size 272x32. My objective is to find the minimum in each column, and store them in an array of 32 elements. To execute this I have created a for loop iterating over the range of columns in dataframe. However, upon assigning the values to be global the output stored has only the last value. But, I would like it to have minimum of column as each entry in array which I can use it for matrix arithmetic operations.

The code snippet:

n = ncol(variables)

for i in 1:n

    global mins = minimum(variables[!, i])
    global maxs = maximum(variables[!, i])

end

Please advice to resolve this issue.

Regards,


Solution

  • I am not 100% sure if this is what you are asking for but it seems it is:

    mins = minimum.(eachcol(variables))
    maxs = maximum.(eachcol(variables))