I have a big matrix (2160x2160), where first I would like to define a block matrix (say 20x20) and fill the diagonal block matrix with 0s. I am struggling on how to achieve this.
For example:
From the matrix
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 1 2 3 4 5 6 7 8 9
[2,] 11 12 13 14 15 16 17 18 19
[3,] 21 22 23 24 25 26 27 28 29
[4,] 31 32 33 34 35 36 37 38 39
[5,] 41 42 43 44 45 46 47 48 49
[6,] 51 52 53 54 55 56 57 58 59
[7,] 61 62 63 64 65 66 67 68 69
[8,] 71 72 73 74 75 76 77 78 79
[9,] 81 82 83 84 85 86 87 88 89
I would first like to define the block matrix as a 3x3, and then fill the diagonal-block of the original matrix with zeros, my final intended result of the example would be:
[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9]
[1,] 0 0 0 4 5 6 7 8 9
[2,] 0 0 0 14 15 16 17 18 19
[3,] 0 0 0 24 25 26 27 28 29
[4,] 31 32 33 0 0 0 37 38 39
[5,] 41 42 43 0 0 0 47 48 49
[6,] 51 52 53 0 0 0 57 58 59
[7,] 61 62 63 64 65 66 0 0 0
[8,] 71 72 73 74 75 76 0 0 0
[9,] 81 82 83 84 85 86 0 0 0
I have been able to define a block matrix through the function as.blockmatrix of the blockmatrix library. I suppose that I should break the blocks in sub-matrices fill the ones that I need with 0 and then re-build my original matrix with the diagonals changed, but I am having difficulty doing this. Any other ideas to achieve this are also welcome (outside the potential solution with the blockmatrix library)
I have also looked at the bdiag function instide the Matrix package and also at the adiag function under magic, but ran out of ideas.
Thanks in advance for your help!