title: Joining two time series based on id and time
body: <p>I want to join two time series based on a ID variable.</p>
  <p>My first time series,</p>
  <pre><code>library(tidyverse)
  library(lubridate)
  
  id &lt;- c(11, 11, 11, 12, 12)
  time &lt;- c(&quot;2020-11&quot;, &quot;2020-12&quot;, &quot;2021-01&quot;, &quot;2020-12&quot;, &quot;2021-01&quot;)
  values &lt;- c(10, 20, 25, 100, 200)
  data1 &lt;- data.frame(id, time, values)
  data1$time &lt;- ym(data1$time)
  </code></pre>
  <p>The second time series is as follows,</p>
  <pre><code>time &lt;- c(&quot;2020-10&quot;, &quot;2020-11&quot;, &quot;2020-12&quot;, &quot;2021-01&quot;, &quot;2020-12&quot;, &quot;2021-01&quot;, &quot;2021-02&quot;)
  trend &lt;- c(0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7)
  data2 &lt;- data.frame(Time, trend)
  data2$time &lt;- ym(data2$time)
  </code></pre>
  <p>Notice that, the first data frame has 5 rows and the second one has 7. The joined data frame should have 5 rows.</p>
  <p>Now I want to join the second data frame into the first by id and date. I am doing the following,</p>
  <pre><code>newdata &lt;- dplyr::inner_join(data1, data2, by = &quot;time&quot;)
  newdata
  &gt; newData
    id       Time values trend
  1 11 2020-11-01     10   0.2
  2 11 2020-12-01     20   0.3
  3 11 2020-12-01     20   0.5
  4 11 2021-01-01     25   0.4
  5 11 2021-01-01     25   0.6
  6 12 2020-12-01    100   0.3
  7 12 2020-12-01    100   0.5
  8 12 2021-01-01    200   0.4
  9 12 2021-01-01    200   0.6
  </code></pre>
  <p>This is not what I want. There are repeatation in the id. The data frame has 9 rows instead of 5. My expected output should look like,</p>
  <pre><code>&gt; newData
    id       time values trend
  1 11 2020-11-01     10   0.2
  2 11 2020-12-01     20   0.3
  3 11 2021-01-01     25   0.4
  4 12 2020-12-01    100   0.3
  5 12 2021-01-01    200   0.4
  </code></pre>
  <p>Any idea how to achieve this?</p>