Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a vector of matrices of different dimension in R

Tags:

r

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.

like image 722
Ryan Warnick Avatar asked Mar 10 '13 03:03

Ryan Warnick


1 Answers

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]]
like image 163
Dason Avatar answered Nov 15 '22 05:11

Dason