title: How to reformat an R data frame with multiple rows into one row
body: <p>I have data frames like the following that I need to reformat into a single row, so that I can create a new data frame that's a collection of many of the simpler data frames, with one row in the new data frame representing all of the data of one of the simpler original data frames.</p>
  
  <p>Here's a trivial example of the format of the original data frames:</p>
  
  <pre><code>&gt; myDf = data.frame(Seconds=seq(0,1,.25), s1=seq(0,8,2), s2=seq(1,9,2))
  &gt; 
  &gt; myDf
    Seconds s1 s2
  1    0.00  0  1
  2    0.25  2  3
  3    0.50  4  5
  4    0.75  6  7
  5    1.00  8  9
  </code></pre>
  
  <p>And below is what I want it to look like after being reformatted. Each column indicates rXsY, where "rX" indicates the row number of the original data frame, and "sY" indicates the "s1" or "s2" column of the original data frame. The "Seconds" column is omitted in the new data frame, as its information is implicit in the row number.</p>
  
  <pre><code>&gt; myNewDf
    r1s1 r1s2 r2s1 r2s2 r3s1 r3s2 r4s1 r4s2 r5s1 r5s2
  1    0    1    2    3    4    5    6    7    8    9
  </code></pre>
  
  <p>I suspect this is really simple and probably involves some combination of <code>reshape()</code>, <code>melt()</code>, and/or <code>cast()</code>, but the proper incantations are escaping me. I could post what I've tried, but I think it would just distract from what's probably a simple question? If anyone would like me to do so, just ask in the comments.</p>
  
  <p>The ideal solution would also somehow programmatically generate the new column names based on the original data frame's column names, since the column names won't always be the same. Also, if it's not difficult, can I somehow simultaneously do this same operation to a list of similar data frames (all the same number of rows, all the same column names, but with differing values in their s1 &amp; s2 columns)? Ultimately I need a single data frame that contains the data from multiple simpler data frames, like this...</p>
  
  <pre><code>&gt; myCombinedNewDf # data combined from 4 separate original data frames
    r1s1 r1s2 r2s1 r2s2 r3s1 r3s2 r4s1 r4s2 r5s1 r5s2
  1    0    1    2    3    4    5    6    7    8    9
  2   10   11   12   13   14   15   16   17   18   19
  3   20   21   22   23   24   25   26   27   28   29
  4   30   31   32   33   34   35   36   37   38   39
  </code></pre>