R creating an array of matrices

I would like to create an array of matrices in such a way as to first create an array of k-matrices with NA values, and then iterate over k and update each k-dimensional matrix through the array.

Any suggestions?

+5
source share
2 answers

I probably miss the point, but will not:

k = 2; n=3; m = 4
array(NA, c(n,m,k))

, , 1

     [,1] [,2] [,3] [,4]
[1,]   NA   NA   NA   NA
[2,]   NA   NA   NA   NA
[3,]   NA   NA   NA   NA

, , 2

     [,1] [,2] [,3] [,4]
[1,]   NA   NA   NA   NA
[2,]   NA   NA   NA   NA
[3,]   NA   NA   NA   NA

give you what you want? Then you can loop as usual:

R> for(k in 1:2){print(a[,,k])}
+8
source

:-). CSGillespie, N- R. list, . , . , .

.

mat1 <- matrix(NA, 3,5)
mat2 <- matrix(NA, 4,7)
matlist <- list(mat1=mat1,mat2=mat2)
+2

All Articles