title: Melting dataframe in R
body: <p>I have the following R dataframe :</p>
  <pre><code>foo &lt;- data.frame(&quot;Department&quot; = c('IT', 'IT', 'Sales'),
                    &quot;Name.boy&quot; = c('John', 'Mark', 'Louis'), 
                    &quot;Age.boy&quot; = c(21,23,44), 
                    &quot;Name.girl&quot; = c('Jane', 'Charlotte', 'Denise'), 
                    &quot;Age.girl&quot; = c(16,25,32))
  </code></pre>
  <p>which looks like the following :</p>
  <pre><code>    
  Department Name.boy Age.boy Name.girl Age.girl
  IT         John     21      Jane      16
  IT         Mark     23      Charlotte 25
  Sales      Louis    44      Denise    32
  </code></pre>
  <p>How do I 'melt' the dataframe, so that for a given Department, I have three columns : Name, Age, and Sex ?</p>
  <pre><code>Department Name       Age   Sex
  IT         John       21    Boy
  IT         Jane       16    Girl
  IT         Mark       23    Boy
  IT         Charlotte  25    Girl
  Sales      Louis      44    Boy
  Sales      Denise     32    Girl
  </code></pre>