title: Alternative to expand.grid for data.frames
body: <p>I have a data.frame <code>df</code> and I want that every row in this <code>df</code> is duplicated <code>lengthTime</code> times and that a new column is added that counts from 1 to <code>lengthTime</code> for each row in <code>df</code>.</p>
  
  <p>I know, it sounds pretty complicated, but what I basically want is to apply <code>expand.grid</code> to <code>df</code>. Here is an ugly workaround and I have the feeling that there most be an easier solution (maybe even a base-R function?):</p>
  
  <pre><code>df &lt;- data.frame(ID   = rep(letters[1:3], each=3),
                   CatA = rep(1:3, times = 3),
                   CatB = letters[1:9])
  lengthTime &lt;- 3
  nrRow &lt;- nrow(df)
  intDF &lt;- df
  for (i in 1:(lengthTime - 1)) {
    df &lt;- rbind(df, intDF)
  }
  df$Time &lt;- rep(1:lengthTime, each=nrRow)
  </code></pre>
  
  <p>I thought that I could just use <code>expand.grid(df, 1:lengthTime)</code>, but that does not work. <code>outer</code> did not bring any luck either. So does anyone know a good solution?</p>