Given a matrix A
of dimension n x n
, my objective is to get all submatrices A[1:mid, (mid+1):n]
and convert them as a list of vectors. Here mid
runs from 1
to n-1
.
For example, if A = matrix(1:16, 4, 4)
, then the result will be res = list(as.vector(A[1:1,2:4]), as.vector(A[1:2,3:4]), as.vector(A[1:3,4:4]))
. A for loop can achieve this but it takes lots of time when n
is huge.