title: R: create a data frame out of a rolling window
body: <p>Lets say I have a data frame with the following structure:</p>
  
  <pre><code>DF &lt;- data.frame(x = 0:4, y = 5:9)
  &gt; DF
    x y
  1 0 5
  2 1 6
  3 2 7
  4 3 8
  5 4 9
  </code></pre>
  
  <p>what is the most efficient way to turn 'DF' into a data frame with the following structure:</p>
  
  <pre><code>w x y
  1 0 5
  1 1 6
  2 1 6
  2 2 7
  3 2 7
  3 3 8
  4 3 8
  4 4 9
  </code></pre>
  
  <p>Where w is a length 2 window rolling through the dataframe 'DF.'  The length of the window should be arbitrary, i.e a length of 3 yields</p>
  
  <pre><code>w x y
  1 0 5
  1 1 6
  1 2 7
  2 1 6
  2 2 7
  2 3 8
  3 2 7
  3 3 8
  3 4 9
  </code></pre>
  
  <p>I am a bit stumped by this problem, because the data frame can also contain an arbitrary number of columns, i.e. w,x,y,z etc.</p>
  
  <p>/edit 2: I've realized edit 1 is a bit unreasonable, as xts doesn't seem to deal with multiple observations per data point</p>