I would like to use the diag() function on a list of vectors, so as to get a list of matrices where the diagonals are the vectors of my list.
To be more specific, suppose I have a list called list
of 100 vectors with 14 values each.
>dim(list)
100 14
I would like to create an array array
of 100 matrices of size 14x14, where the diagonal of the matrix diag2vec(array[i,,])
is my vector list[i,]
(all other values in the matrix to be 0
).
So I would end up with:
>dim(array)
100 14 14
I tried using the diag() function, but I cannot get it to work row-wise.