title: How do I specify a sort order using a list?
body: <p>Forgive my ignorance, but I'm having trouble with sorting a data frame. I would like to specify an ordered list like <code>c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")</code> when sorting such that the dataframe is sorted in the order of the list.</p>
  
  <p>In this example, I would like to start with</p>
  
  <pre><code>    Day Present Count
      Fri No  164
      Fri Yes 131
      Mon No  142
      Mon Yes 174
      Sat No  39
      Sat Yes 26
      Sun No  44
      Sun Yes 39
      Thu No  191
      Thu Yes 192
      Tue No  184
      Tue Yes 214
      Wed No  343
      Wed Yes 255
  </code></pre>
  
  <p>And end with</p>
  
  <pre><code>    Day Present Count
      Mon No  142
      Mon Yes 174
      Tue No  184
      Tue Yes 214
      Wed No  343
      Wed Yes 255
      Thu No  191
      Thu Yes 192
      Fri No  164
      Fri Yes 131
      Sat No  39
      Sat Yes 26
      Sun No  44
      Sun Yes 39
  </code></pre>
  
  <p>I've tried <code>perday[do.call(order, perday[c("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")]),]</code> but I get "undefined columns selected". I get the same error if there are 14 entries in the character vector too, so I'm really confused at this point.</p>
  
  <p>Here's the dput:</p>
  
  <pre><code>perday&lt;-structure(list(dayofweek = c("Fri", "Fri", "Mon", "Mon", "Sat", 
  "Sat", "Sun", "Sun", "Thu", "Thu", "Tue", "Tue", "Wed", "Wed"
  ), Attended = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 
  2L, 1L, 2L, 1L, 2L), .Label = c("No", "Yes"), class = "factor"), 
      nrow = c(164L, 131L, 142L, 174L, 39L, 26L, 44L, 39L, 191L, 
      192L, 184L, 214L, 343L, 255L)), .Names = c("dayofweek", "Attended", 
  "nrow"), row.names = c(NA, -14L), class = "data.frame")
  </code></pre>