title: Assign Value to Diagonal Entries of Matrix
body: <p>I need to access and assign single slots of an m*n matrix inside a for loop. The code so far:</p>
  
  <pre><code>rowCount &lt;- 9
  similMatrix = matrix(nrow = rowCount - 1, ncol = rowCount)
  show(similMatrix)
  for(i in (rowCount - 1)){
    for (j in rowCount)
      if (i == j){
        similMatrix[i == j] &lt;- 0;
      }
  }
  show(similMatrix)
  </code></pre>
  
  <p>so if i = j the NA value in the matrix needs to be replaced with 0.</p>