title: Changing blocks of values in a large matrix in R
body: <p>I have large matrix of 1000x1000 entries. The 1's are organized in blocks, they always seperated from the other blocks by not overlapping on the row or column of the next block. To give you an example with a 12x12 matrix that consists of 3 blocks of 1s: </p>
  
  <pre><code>      111100000000
        111100000000
        111100000000
        111100000000
        000011110000
        000011110000
        000011110000
        000011110000
        000000001111
        000000001111
        000000001111
        000000001111
  </code></pre>
  
  <p>I want R to transfer the matrix into something like this(no matter the size of the matrix):</p>
  
  <pre><code>      111100000000
        111100000000
        111100000000
        111100000000
        000022220000
        000022220000
        000022220000
        000022220000
        000000003333
        000000003333
        000000003333
        000000003333
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Data</strong></p>
  
  <pre><code>structure(c(1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 
  0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 
  1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 
  0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 
  0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
  0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 
  0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 
  1), .Dim = c(12L, 12L))
  </code></pre>