DataFrames: how to convert many arrays into a data frame?

Suppose I ran different loops in a notebook. In each one, I obtain e,g., a 1×120 Matrix{Float64} array. I want to collect some of them in a data frame. I know how to do it (please, see MWE below). However, I find my clumsy code both primate and inefficient. There must be a way to make it more appealing and efficient. Unfortunately, my limited knowledge of DataFrames precludes me from providing a solution to this problem. Some help would be very much appreciated. Thanks.

df1 = DataFrame(y1',[:a1])
df2 = DataFrame(k1',[:a2])
df3 = DataFrame(n1',[:a3])
df4 = DataFrame(time, [:t])
irfs = hcat(df4, df1, df2, df3) #, makeunique=true)

guess you could just perform cat first then transpose, haven’t tested yet

A = [t; a1; a2; a3]
C = [:t, :a1, :a2, :a3]

d = DataFrame(A', C)
1 Like

I would write

DataFrame(t=t, a1=vec(y1), a2=vec(k1), a3=vec(n1))
1 Like

@sijo, @L_Adam, thanks for helping. I have tested @sijo’s solution because it looks more straightforward and intuitive. It is simply amazing how good solutions are ridiculously simple … for those who know it. Thanks a lot.

1 Like