How can I create a vector of matrices of different dimension in R. For example say I have two matrices
M1=array(0,dim=c(2,2))
M2=array(0,dim=c(3,3))
Then I can make a vector C containing these matrices such that
C[1]=M1
and
C[2]=M2.
I know that I can create a 3 dimensional array
C=array(NA,dim=c(2,3,3)
but the only way I know how to do this has to have the
C[1,,]
element in the array have more space then necessary.
Use a list
C <- list()
C[[1]] <- array(0,dim=c(2,2))
C[[2]] <- array(0,dim=c(3,3))
C[[1]][1,1] <- 5
C[[1]]
C[[2]]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With