Insert row at a specific location in matrix using R
<p>I'm trying to add rows to a matrix at particular locations, where the locations are contained in a vector. The schema below shows the inputs and the expected outcome. I tried to use a "for" loop but couldn't make it work. Any suggestions help.</p>

<p>Source Matrix (6x3)</p>

<pre><code>(1) 1   2   3
(2) 4   5   6
(3) 7   8   9
(4) 6   9   2
(5) 3   6   1
(6) 2   2   7
</code></pre>

<p>Vector of locations (indicates the row in the source matrix that will contain zeros)</p>

<pre><code>[2, 5, 6]  
</code></pre>

<p>Result Matrix(6+length.vector x 3)</p>

<pre><code>(1) 1   2   3
(2*)0   0   0
(3) 4   5   6
(4) 7   8   9
(5*)0   0   0
(6*)0   0   0
(7) 6   9   2
(8) 3   6   1
(9) 2   2   7
</code></pre>