title: How to reshape a dataframe for analysis by creating new variables based on row values
body: <p>Is there a way I can get  <code>newdf</code> from <code>olddf</code>, by creating a new variable for the column name and a variable for the result? Thank you.</p>
  <pre><code>olddf &lt;- data.frame('A' = c('Z1','Z2','Z3'), 
                      'B' = c(100, 200, 500),
                      'C' = c(90, 50, 60),
                      'D' = c(NA, 50, NA))
  
  newdf &lt;- data.frame('A' = c('Z1','Z2','Z3','Z1','Z2','Z3'), 
                      'B' = c(100, 200, 500, 100, 200, 500),
                      'var' = c('C', 'C', 'C', 'D', 'D', 'D'),
                      'res' = c(90, 50, 60, NA, 50, NA))
  </code></pre>