Creating diagonal matrix (diag) from Excel sheet

Well, this is not a reproducible example. It is a screenshot from your code. Please go through the link I shared to understand how to make one. It's a really really helpful post.

That being said, let me try to suggest some steps.

  1. You mentioned that USEEI0v1_1_Matrices_B is read correctly. Confirm it before proceeding.

  2. In that case, most probably USEEI0v1_1_Matrices_B[265, 2:389] will also be correct, but check that. Also, is it a vector?

  3. Now, you want a 388 by 388 diagonal matrix with diagonal entries being the entries of USEEI0v1_1_Matrices_B[265, 2:389], right? So, try with Rnox.diag <- diag(x = USEEI0v1_1_Matrices_B[265, 2:389]).

Let us know your findings.

Just to note, you can create a k-dimensional identity matrix by diag(x = k), where k \in \mathbb{N}. You don't need to create a k by k zero matrix and change diagonals to unity afterwards.

1 Like