title: Why is data.table join not working with dates?
body: <p><code>data.table</code> join is not selecting the maximum date, but is the maximum value. See the following example:</p>
  
  <pre><code>table1 &lt;- fread(
    "individual_id | date       
         1             |  2018-01-06
         2             |  2018-01-06", 
    sep ="|"
  )
  table1$date = as.IDate(table1$date)
  table2 &lt;- fread(
    "individual_id | date_second       | company_id | value
         1             |  2018-01-02 |     62       |  1     
         1             |  2018-01-04 |     62       |  1.5 
         1             |  2018-01-05 |     63       |  1   
         2             |  2018-01-01 |     71       |  2     
         2             |  2018-01-02 |     74       |  1   
         2             |  2018-01-05 |     74       |  4",
    sep = "|"
  )
  table2$date_second = as.IDate(table2$date_second)
  </code></pre>
  
  <p>The following join should select the maximum value by company id and then select the return the maximum of all the values returned for each individual.
  The join to select max value:</p>
  
  <pre><code>table2[table1, on=.(individual_id, date_second&lt;=date), 
         #for each row of table1,
         by=.EACHI,
         # get the maximum value by company_id and the max of all of these
         max(.SD[,max(value), by=.(company_id)]$V1)]
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>   individual_id date_second  V1
  1:             1  2018-01-06 1.5
  2:             2  2018-01-06 4.0
  </code></pre>
  
  <p>same join, selecting max date:</p>
  
  <pre><code>table2[table1, on=.(individual_id, date_second&lt;=date), 
         #for each row of table1,
         by=.EACHI,
         # get the maximum date by company_id and the max of all of these
         max(.SD[,max(date_second), by=.(company_id)]$V1)]
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>   individual_id date_second         V1
  1:             1  2018-01-06 2018-01-02
  2:             2  2018-01-06 2018-01-01
  </code></pre>
  
  <p>Why is it not returning the max date like it did the max value?</p>