title: How can I add a row manually to a dataframe?
body: <p>This is probably a very simple answer, but I am not able to find a solution. </p>
  
  <p>I have a dataframe:</p>
  
  <pre><code> structure(list(year = structure(1:23, .Label = c("1990", "1991", 
  "1992", "1993", "1994", "1995", "1996", "1997", "1998", "1999", 
  "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", 
  "2008", "2010", "2011", "2012", "2013"), class = "factor"), val = c(8, 
  3, 1, 17, 5, 9, 6, 7, 3, 15, 11, 6, 2, 11, 15, 11, 15, 1, 14, 
  2, 15, 4, 6)), .Names = c("year", "val"), row.names = c(NA, -23L
  ), class = "data.frame")
  </code></pre>
  
  <p>I want to add a row manually (year=2009, val=20) right between 2008 and 2010 year.</p>
  
  <p>I am doing this using <a href="https://stackoverflow.com/questions/11561856/add-new-row-to-dataframe">Add new row to dataframe, at specific row-index, not appended?</a>:</p>
  
  <p><strong>#1</strong></p>
  
  <pre><code>r&lt;-seq(4)
  newrow&lt;-c(2009,5)
  insertRow &lt;- function(df, newrow, r) {
    df[seq(r+1,nrow(df)+1),] &lt;- df[seq(r,nrow(df)),]
    df[r,] &lt;- newrow
    df
  }
  
  insertRow(df, newrow, r)
  </code></pre>
  
  <p>But I am getting this:</p>
  
  <pre><code>Error in seq.default(r, nrow(df)) : 
    'from' must be of length 1 
  </code></pre>
  
  <p><strong>#2</strong></p>
  
  <pre><code>newrow&lt;-c(2009,20)
  rbind(df,newrow)
  
  Warning message:
  In `[&lt;-.factor`(`*tmp*`, ri, value = c(1L, 2L, 3L, 4L, 5L, 6L, 7L,  :
    invalid factor level, NA generated
  </code></pre>