I have an array (y) of 500, 6X6 matrices, like this:
, , 1
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.0000 0.3627 0.4132 0.4231 0.3795 0.5444
[2,] 0.3627 0.0000 0.2084 0.3523 0.2310 0.5377
[3,] 0.4132 0.2084 0.0000 0.1984 0.2920 0.4774
[4,] 0.4231 0.3523 0.1984 0.0000 0.2787 0.4363
[5,] 0.3795 0.2310 0.2920 0.2787 0.0000 0.5129
[6,] 0.5444 0.5377 0.4774 0.4363 0.5129 0.0000
[...]
, , 500
[,1] [,2] [,3] [,4] [,5] [,6]
[1,] 0.0000 0.3755 0.3568 0.3835 0.3582 0.5065
[2,] 0.3755 0.0000 0.0840 0.2253 0.2237 0.4066
[3,] 0.3568 0.0840 0.0000 0.1673 0.2434 0.4073
[4,] 0.3835 0.2253 0.1673 0.0000 0.2338 0.3403
[5,] 0.3582 0.2237 0.2434 0.2338 0.0000 0.4263
[6,] 0.5065 0.4066 0.4073 0.3403 0.4263 0.0000
I want to extract each matrix position (36) through all the 500 matrices in the array and store the 500 values of each position in a separate vector (36 vectors of 500 values).
Up till now, with the aid obtained here, I can extract the 500 values of a specific position (1,1 in this case) and store them in a vector called, say, "unouno", with this code:
unouno<-NULL
for (i in 1:dim(y)[[3]]){
unouno[i]<-y[1,1,i]
}
I could write 36 times this code and extract all values, but how could I automate this? Should I use nested loops (I ve tried them unsuccesfully) or is there any other better way? Thanks!