[R] is it possible to form matrix of matrices...and multiple arrays
Gabor Grothendieck
ggrothendieck at gmail.com
Thu Sep 29 03:33:37 CEST 2005
On 9/28/05, booop booop <booopi at yahoo.com> wrote:
> Dear sirs,
> 1...........Kindly tell me is it possible to form a matrix which contains a no of matrices..
> for eg..
> if a,b,c,d are matrices....
> and e is a matrix which contains a,b,c,d as rows and columns..
Try this:
mat <- list(diag(2), diag(3), diag(4), diag(5))
dim(mat) <- c(2,2)
mat
mat[[1,1]]
>
> 2..........Is it possible to form array of array of arrays
>
> for eg..
> "A" contains two set of arrays (1,2)...and each A[1] and A[2] individually contains two set of arrays
> I tried like
> p<-list()
> pa[[[1]]] [[1]] [1]<-matrix(1,2,2)
> pa[[[1]]] [[1]] [2]<-matrix(2,2,2)
>
> But its not working..kindly tell me whether my approach is wrong or not?..
Try this. arr is set to a 2x2x2 array filled with diagonal matrices.
Then we set two elements of it to constant matrices.
arr <- lapply(2:9, diag)
dim(arr) <- c(2,2,2)
arr[[1,1,1]]
arr
arr[[1,1,1]] <- matrix(1,2,2)
arr[[1,1,2]] <- matrix(2,2,2)
arr[[1,1,1]]
arr[[1,1,2]]
More information about the R-help
mailing list