title: Ordering and filtering a dataframe by a factor
body: <p>Given </p>
  
  <pre><code>x&lt;-data.frame(age=sample(1:10), gender=c("M","F"))
  </code></pre>
  
  <p>How do I select the rows with gender 'M', and order by age ?</p>
  
  <p>I know I can order the dataframe by age with :
     x[order(x$age),]</p>
  
  <p>And I can select the rows with gender 'M' with:
      x[x$gender=='M',]</p>
  
  <p>And finally, I can do both with:
      y&lt;-x[x$gender=='M',]
      y&lt;-y[order(y$age),]</p>
  
  <p>Is there a way to more concisely do this ?</p>
  
  <p>I've tried</p>
  
  <pre><code>x[x$gender=='M' &amp; order(x$age),]
  and 
  x[x$gender=='M' &amp; order(x$age),]
  </code></pre>
  
  <p>which filters but does not order.</p>
  
  <pre><code>&gt; x[x$gender=='M' &amp;order(x$age),]
    age gender
  1   4      M
  3   6      M
  5   3      M
  7   1      M
  9   9      M
  </code></pre>
  
  <p>I've also tried</p>
  
  <pre><code>x[x$gender=='M' &amp;&amp;order(x$age),]
  </code></pre>
  
  <p>Which doesn't seem to filter or order (I confess I don't understand the difference between &amp; and &amp;&amp;).</p>
  
  <pre><code>   age gender
  
  1    4      M
  2    5      F
  3    6      M
  4    2      F
  5    3      M
  6   10      F
  7    1      M
  8    8      F
  9    9      M
  10   7      F
  </code></pre>
  
  <p>What am I doing wrong ?</p>
  
  <p>Note: My question is slightly different from <a href="https://stackoverflow.com/questions/21297989">the one asked here</a>; I'm specifically trying to understand why my approach(es) don't work.  That question asks for an answer but neither it nor its answers  help to explain what was wrong with the specific approaches tried here.</p>