title: R code - clever loop to add rows
body: <p>Lets say I have a dataset where rows keep falling out as I go through the days, and I want to add these rows in again.</p>
  
  <p>Example with missing rows:</p>
  
  <pre><code>Fruits &lt;- c(rep(c("apples","oranges","pears","kiwis"),3),
      "bananas","oranges","pears","kiwis","bananas","pears","kiwis","bananas")
  Days &lt;- c(rep("Monday",4),rep("Tuesday",4),rep("Wednesday",5),
      rep("Thursday",4),rep("Friday",3))
  Amounts &lt;- c(10,15,20,20,10,15,20,20,10,15,20,20,25,15,20,20,25,20,20,25)
  dfmissing &lt;- data.frame(Fruits,Days,Amounts)
  </code></pre>
  
  <p>And I want it to fill new rows on Thursday and Friday when "apples" and "oranges" drop out as such.</p>
  
  <p>Note that "bananas" appears for the first time on Wednesday, which complicates matters a little.</p>
  
  <p>The completed table should look like the following</p>
  
  <pre><code>Fruits &lt;- c(rep(c("apples","oranges","pears","kiwis"),2), 
      rep(c("apples","oranges","pears","kiwis","bananas"),3))
  Days &lt;- c(rep("Monday",4),rep("Tuesday",4),
      rep("Wednesday",5),rep("Thursday",5),rep("Friday",5))
  Amounts &lt;- c(rep(c("10","15","20","20"),2),rep(c("10","15","20","20","25"),3))
  dfcomplete &lt;- data.frame(Fruits,Days,Amounts)
  </code></pre>
  
  <p>Comparing the two tables</p>
  
  <pre><code>dfmissing
  dfcomplete
  </code></pre>
  
  <p>Assume there is only one week of data so "Monday" never gets repeated etc - the column "Days" is a list of unique factors.</p>
  
  <p>Thanks in advance.</p>