title: R: How to get the maximum value of a datetime column in a time series data
body: <p>I am working on a time series data. I have 2 date time columns and 1 fiscal week column. I have given an example where I have a situation like below and I need to get the MAX of the EditDate. </p>
  
  <pre><code>EditDate &lt;- c("2015-04-01 11:40:13", "2015-04-03 02:54:45","2015-04-07 11:40:13")
  ID &lt;- c("DL1X8", "DL1X8","DL1X8")
  Avg &lt;- c(38.1517, 38.1517, 38.1517)
  Sig &lt;- c(11.45880000, 11.45880000, 11.45880000)
  InsertDate &lt;- c("2015-04-03 9:40:00", "2015-04-03 9:40:00",2015-04-10 9:40:00)
  FW &lt;- c("39","39","40")
  
  df1 &lt;- data.frame(EditDate , ID, Avg, Sig, InsertDate, FW)
  </code></pre>
  
  <p>This returns </p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>+---------------------+-------+---------+-------------+--------------------+----+
  |   EditDate          | ID    | Avg     |   Sig       |    InsertDate      | FW |
  +---------------------+-------+---------+-------------+--------------------+----+
  | 2015-04-01 11:40:13 | DL1X8 | 38.1517 | 11.45880000 | 2015-04-03 9:40:00 | 39 |
  | 2015-04-03 02:54:45 | DL1X8 | 38.1517 | 11.45880000 | 2015-04-03 9:40:00 | 39 |
  | 2015-04-07 11:40:13 | DL1X8 | 38.1517 | 11.45880000 | 2015-04-10 9:40:00 | 40 |
  +---------------------+-------+---------+-------------+--------------------+----+
  </code></pre>
  
  <p>The desired output that I want is </p>
  
  
  
  <pre class="lang-html prettyprint-override"><code>+---------------------+-------+---------+-------------+--------------------+----+
  |   EditDate          | ID    | Avg     |   Sig       |    InsertDate      | FW |
  +---------------------+-------+---------+-------------+--------------------+----+
  | 2015-04-07 11:40:13 | DL1X8 | 38.1517 | 11.45880000 | 2015-04-10 9:40:00 | 40 |
  +---------------------+-------+---------+-------------+--------------------+----+
  </code></pre>
  
  <p>I tried using sqldf  using the library(RH2) but it takes a lot of time to run. </p>
  
  <pre><code>df2 &lt;- sqldf("SELECT * FROM df1 
                          WHERE (EditDate = (SELECT MAX(EditDate) FROM df1))
                          ORDER BY EditDate ASC")
  </code></pre>
  
  <p>I am not sure if it could be done using the dplyr package. Could someone provide inputs on how I could optimize this using dplyr or any other alternatives? </p>