How to create a DataFrame from 1×24×24 Array{Float64, 3}

Hi. I have a matrix named “cycles” which is a 72×24 Matrix{Float64}. I want to obtain a cross-correlation matrix associated with its 24 columns. No problem with this:

Cross_Corr_matrix = crosscor(cycles[:,:],cycles[:,:], [0]; demean=true)

which provides the following output:

1×24×24 Array{Float64, 3}:
[:, :, 1] =
 1.0  0.216743  -0.0920911  -0.00388045  …  0.0603473  0.0339215  0.0944969

[:, :, 2] =
 0.216743  1.0  0.0569839  0.293187  …  0.429425  0.478719  0.534698

[:, :, 3] =
 -0.0920911  0.0569839  1.0  0.246218  …  0.0632372  -0.180101  0.303093

...

[:, :, 22] =
 0.0603473  0.429425  0.0632372  0.25062  …  0.517531  1.0  0.49417  0.524282

[:, :, 23] =
 0.0339215  0.478719  -0.180101  …  0.407871  0.49417  1.0  0.448303

[:, :, 24] =
 0.0944969  0.534698  0.303093  …  0.343121  0.524282  0.448303  1.0

My question is: how can I transform this output into a data frame?

I tried:

df_corr = DataFrame(Cross_Corr_matrix)

which produced the following error:

LoadError: ArgumentError: 'Array{Float64, 3}' iterates 'Float64' values, which doesn't satisfy the Tables.jl `AbstractRow` interface 
ArgumentError: 'Array{Float64, 3}' iterates 'Float64' values, which doesn't satisfy the Tables.jl `AbstractRow` interface

Help will be very much appreciated. Thanks.

reshape(cross_corr_matrix, 24, 24) may help

2 Likes

@AquaIndigo, thanks a lot. It’s so simple! Quite embarrassing after one spends two hours trying to figure out a solution and get none.

Another way is dropdims(cross_corr_matrix, dims=1), which will just call reshape but means you need not handle the sizes.

3 Likes

@mcabbott Thanks. It works and its simplicity is striking.