title: Get the latest record based on multiple columns - R
body: <p>I am trying to extract the latest record based on a combination of 3 columns. Below is my data along with the code to generate it:</p>
  
  <p><a href="https://i.stack.imgur.com/nHO2E.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nHO2E.png" alt="enter image description here"></a></p>
  
  <pre><code>test_df &lt;- data.frame(KEY = c("AB101", "AB101","AB101" ,"PE105", "PE105", "PE105", "AB105", "AB105"), 
                       date = c("2014-08-26", "2014-08-26", "2014-05-26", "2015-12-23", "2015-12-23", 
                                "2015-10-23", "2016-09-23", "2016-09-23"),
                       decision = c("Accepted", "Rejected", "Rejected", "Accepted", "Rejected", "Rejected", 
                                    "Accepted", "Rejected"), 
                       date_time = c("2017-12-18 10:31:25", "2017-12-18 10:31:25", "2016-12-18 10:31:25", "2016-12-18 10:31:25",
                                     "2018-08-18 10:31:25", "2018-08-18 10:31:25", "2017-12-18 10:31:25", "2018-01-18 10:31:25"),
                       seq_num = c(104, 78, 84, 111, 89, 120, 102, 71))
  </code></pre>
  
  <p>I want to use the date, date_time and seq_num (in this order) to get the latest record:</p>
  
  <p>Ideally the output should be like this:</p>
  
  <p><a href="https://i.stack.imgur.com/AY38X.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AY38X.png" alt="enter image description here"></a></p>
  
  <p>NOTE: The seq_num should be 78 instead of 104.
  So, the logic should say something like this:</p>
  
  <p>Get the record with the maximum <code>date</code>. This will result in multiple rows, so then It should look at the <code>Date_time</code> column, which again could possibly result in multiple rows for each key. Then finally look at the <code>seq_num</code> and pull that row. 
  So far I have the below code which works only on <code>date</code>. how do I add other conditions. Also it would be great if in the output the <code>date_time</code> and <code>date</code> columns could also show, just like the <code>seq_num</code> is showing. </p>
  
  <p>Code:</p>
  
  <pre><code>df5 &lt;- test_df %&gt;% group_by(KEY) %&gt;%
  slice(which.max(date))
  </code></pre>