title: R: Reorder multiple variable groups
body: <p>This is a similar question to <a href="https://stackoverflow.com/questions/28290145/using-rs-plyr-package-to-reorder-groups-within-a-dataframe">reordering groups with dataframe</a>, however differs in that there are more than two variables. Example data:</p>
  
  <pre><code>raw &lt;- "Date          Response     ZNumber     Latency    ZPV
          2016-05-04    1            1           445.562    59.666
          2016-05-04    2            1           433.890    97.285
          2016-05-04    3            1           372.073    53.994
          2016-05-04    4            1           282.337    89.686
          2016-05-04    4            2           333.186    57.471
          2016-05-04    5            1           320.500    71.968
          2016-05-04    5            2           280.818    49.187
          2016-07-14    1            1           411.849    65.539
          2016-07-14    2            1           346.814    50.626"
  data &lt;- read.table(text=raw, header = TRUE)
  </code></pre>
  
  <p>Individual 'Date-Response-ZNumber' and 'Latency-ZPV' is always correctly associated. The ZNumber order per Date-Response should be defined by ascending order of Latency.</p>
  
  <p>The problem in my data is that sometimes when a Date-Response has more than one ZNumber, the Latency order <strong>sometimes</strong> does not match the ZNumber order e.g. Date=2016-05-04, Response=4 has ascending order in both ZNumber and Latency whereas Date=2016-05-04, Response=5 the ZNumber is ascending while Latency is descending. </p>
  
  <p>I cannot discover the correct split-apply-combine operations.</p>
  
  <hr>
  
  <p><strong>Output</strong></p>
  
  <p>What I would like performed is both ZNumber and Latency to ascend together within a 'Date-Response' group e.g. Date=2016-05-04, Response=5 </p>
  
  <pre><code>"Date          Response     ZNumber     Latency    ZPV
  2016-05-04    1            1           445.562    59.666
  2016-05-04    2            1           433.890    97.285
  2016-05-04    3            1           372.073    53.994
  2016-05-04    4            1           282.337    89.686
  2016-05-04    4            2           333.186    57.471
  2016-05-04    5            1           280.818    49.187
  2016-05-04    5            2           320.500    71.968
  2016-07-14    1            1           411.849    65.539
  2016-07-14    2            1           346.814    50.626"
  </code></pre>
  
  <hr>
  
  <p><strong>dplyr</strong></p>
  
  <p>Numerous attempts to solve, such as below, have not worked... </p>
  
  <pre><code>library(dplyr)
  
  data &lt;- data %&gt;%
  group_by(Date, Response) %&gt;%
  arrange(Latency, ZNumber) %&gt;% 
  arrange(Date, Response)
  </code></pre>
  
  <p>or, as suggested in the above linked question...</p>
  
  <pre><code>data &lt;- data %&gt;%
  arrange(df, group, desc(value))
  </code></pre>
  
  <p>with the various 'mutating joins' without success. e.g. </p>
  
  <pre><code>data &lt;- data %&gt;%
    group_by(Date,Response) %&gt;%
    select(Latency) %&gt;%
    arrange(Latency) %&gt;% 
    arrange(Response) %&gt;%
    full_join(data,by=c("Date","Response"))
  </code></pre>
  
  <p>however now has two Latency columns. </p>
  
  <hr>
  
  <pre><code>sessionInfo()
  R version 3.3.2 (2016-10-31)
  Platform: x86_64-w64-mingw32/x64 (64-bit)
  Running under: Windows 7 x64 (build 7601) Service Pack 1
  other attached packages:
  [1] dplyr_0.5.0
  loaded via a namespace (and not attached):
  [1] lazyeval_0.2.0 magrittr_1.5   R6_2.2.0       assertthat_0.1 DBI_0.5-1     
  [6] tools_3.3.2    tibble_1.2     Rcpp_0.12.8 
  </code></pre>