title: Melt and dcast based on the name of the original data frame column
body: <p>I'm having a hard time reshaping a dataframe for use with error bar plots, combining all the columns with centeral-tendency data and, separately, all the columns with error data.</p>
  
  <p>I start with a data frame with a column for the independent variable, and then two columns for each measured parameter: one for the average value, and one for the error, as you'd typically format a spreadsheet with this kind of data.  The initial data frame looks like this:</p>
  
  <pre><code>df&lt;-data.frame(
    indep=1:3, 
    Amean=runif(3), 
    Aerr=rnorm(3), 
    Bmean=runif(3), 
    Berr=rnorm(3)
  )
  </code></pre>
  
  <p>I'd like to use melt and dcast to get it into a form that looks like this:</p>
  
  <pre><code>df.cast&lt;-data.frame(
    indep=rep(1:3, 2), 
    series=c(rep("A", 3), 
    rep("B", 3)), 
    means=runif(6), 
    errs=rnorm(6)
  )
  </code></pre>
  
  <p>So that I can then feed it to ggplot like this:</p>
  
  <pre><code>qplot(data=df.cast, x=indep, y=means, ymin=means-errs, ymax=means+errs, 
        col=series, geom="errorbar")
  </code></pre>
  
  <p>I've been trying to melt and then recast using expressions like this:</p>
  
  <pre><code>df.melt&lt;-melt(df, id.vars="indep")
  dcast(df.melt, 
    indep~(variable=="Amean"|variable=="Bmean") + (variable=="Aerr"|variable=="Berr")
  )
  </code></pre>
  
  <p>but these return a dataframe with funny boolean columns. </p>
  
  <p>I could manually make two dataframes (one for the mean values, one for the errors), melt them separately, and recombine, but surely there must be a more elegant way?</p>