title: R - how to "insert" a value into a row for a fill-in matrix
body: <h2>EDIT</h2>
  <p>Hello, here's a more reproducible example.</p>
  <p>I have an R script that borrows heavily from this <a href="https://www.r-bloggers.com/2013/04/retirement-simulating-wealth-with-random-returns-inflation-and-withdrawals-shiny-web-application/" rel="nofollow noreferrer">blogpost</a> and I'm trying to make some modifications to how the matrix of each simulation is constructed.</p>
  <p>I'm really bad with for-loops in R, so I need a little help figuring it out.</p>
  <p>What I'm hoping to do is find a way to inject a value to (re-baseline) for a certain row (or rows) ... maybe I'm over thinking this and missing something obvious?</p>
  <pre><code># starting cash for each &quot;simulation&quot;
  principle = 100
  
  #starting inflation assumption
  inflation = .05
  
  #starting returns
  returns = .02
  
  # number of time units (lets say months)
  n.obs = 5
  
  # number of simulations (columns)
  n.sim = 5
  
  # time I retire and get access to 401k
    t_retire = 4
      
  # amount of money available to be added to my principal at t==t_retire
    retire = 100
  
  # simulate cases - they're all the same in this example
  nav = matrix(start.capital, n.obs + 1, n.sim)
  for (j in 1:n.obs) {
    nav[j + 1, ] = (nav[j, ] * (1 + returns - inflation))
  }
  </code></pre>
  <p>I want to edit this for-loop to add the &quot;retire&quot; value to my existing &quot;principle&quot; at row (t_retire) = 4.</p>