title: join using data.table in r
body: <p>I have some data like this:</p>
  
  <pre><code>library(data.table)
  # example daycare
  rewards &lt;- data.table(ChildNumber = c(1,1,2,2,3,3), 
                        StartDate = as.Date(c("2015-1-1", "2015-2-1", "2015-3-1", "2015-4-1", "2015-5-1", "2015-6-1")), 
                        EndDate = as.Date(c("2015-2-1", "2015-3-1", "2015-4-1", NA, NA, NA)), 
                        Treat = c("pop", "cookie", "star", "pop", "cookie", "star")
                        )
  awards &lt;- data.table(ChildNumber = c(1,1,1,1,2,2,2,2,3,3,3,3), 
                       StartDate = as.Date(c("2015-1-1", "2015-1-8", "2015-1-15",  
                                             "2015-2-1", "2015-2-8", "2015-2-15", 
                                             "2015-3-1", "2015-3-8", "2015-3-15",  
                                             "2015-4-1", "2015-4-8", "2015-4-15" )), 
                       EndDate = as.Date(c("2015-1-7", "2015-1-14", "2015-1-21", 
                                            "2015-2-7", "2015-2-14", "2015-2-15",  
                                            "2015-3-7", "2015-3-14", "2015-3-15", 
                                            "2015-4-7", "2015-4-14", "2015-4-15" ))
                      )
  </code></pre>
  
  <p>I need to add a Treat column to the awards data.table based on the date range specified in the rewards table.  </p>
  
  <p>I tried this: </p>
  
  <pre><code>merged &lt;- rewards[awards, on=list(ChildNumber, StartDate &gt;= StartDate, EndDate &lt;= EndDate)]
  </code></pre>
  
  <p>but got NAs in the Treat column.   I know the data is not tidy, I guess it needs an ID field. I suppose this is really a non-equi join? Any suggestions?</p>