title: Replacing indices in an array with 1 doesn't work
body: <p>I'm trying to implement an edge detection function for some PNG images in R. My function runs fine - taking an array and making each numeric value the standard deviation of values near it. Then, I find the indices of values in the top 1% of standard deviations in the photo (the edges).</p>
  
  <p>However, I'm running into an odd issue when trying to replace these indices with "1". The code that I've written is below:</p>
  
  <pre><code>vg_new &lt;- vg
  for (i in nrow(outlier_indices)){
    row &lt;- outlier_indices[i,1] ; column &lt;- outlier_indices[i,2]
    vg_new[row, column, 1] &lt;- 1
    vg_new[row, column, 2] &lt;- 1
    vg_new[row, column, 3] &lt;- 1
  }
  </code></pre>
  
  <p>For some background, vg_new (and vg) are the pictures - they're each an array of 3 matrices, each 374x800. outlier_indices is my 64255x2 matrix of indices, the first column being the row index and the second column being the column index.</p>
  
  <p>Thus, I'm trying to replace the correct indices in each color channel (each separate matrix in vg_new) with "1". However, when I run this loop nothing is actually changing. However, when I run something like:</p>
  
  <pre><code>vg_new[50, 1, 1] &lt;- 1
  </code></pre>
  
  <p>the index changes no problem. I've checked to make sure all indices in "outlier_indices" exist in "vg_new" and they all do. Any ideas as to what's going on here? Am I missing something obvious?</p>
  
  <p>Here's a full example:</p>
  
  <pre><code>vg &lt;- array(0, c(374, 800, 3))
  outlier_indices &lt;- matrix(c(1:50), c(1:50), nrow = 50, ncol = 2)
  for (i in nrow(outlier_indices)){
    row &lt;- outlier_indices[i,1] ; column &lt;- outlier_indices[i,2]
    vg[row, column, 1] &lt;- 1
    vg[row, column, 2] &lt;- 2
    vg[row, column, 3] &lt;- 3
  }
  </code></pre>