title: How to sort a data by assigned name for a column
body: <p>I want to use the order() function in R to sort a data by the column. </p>
  
  <p>For example, with the data.frame below </p>
  
  <pre><code>set.seed(1)
  mydata &lt;-as.data.frame(cbind(NUM=seq(1:5),RES=runif(5,0,10)))
  
  &gt; with(data = mydata, mydata[order(RES),])
    NUM      RES
  5   5 2.016819
  1   1 2.655087
  2   2 3.721239
  3   3 5.728534
  4   4 9.082078
  </code></pre>
  
  <p>It's OK. But when I do the same thing with assigned name for a column I got an unexpected result.</p>
  
  <pre><code>colname &lt;- "RES"
  
  &gt; with(data = mydata, mydata[order(colname),])
    NUM      RES
  1   1 2.655087
  </code></pre>
  
  <p>I'm wondering if anybody has faced the same problem and/or if you have a solution for that. Appreciate your help in advance.</p>