title: Aggregate week and date in R by some specific rules
body: <p>I'm not used to using R. I already asked a question on stack overflow and got a great answer.
  I'm sorry to post a similar question, but I tried many times and got the output that I didn't expect.
  This time, I want to do slightly different from my previous question.
  <a href="https://stackoverflow.com/questions/73111233/merge-two-data-with-respect-to-date-and-week-using-r">Merge two data with respect to date and week using R</a>
  I have two data. One has a year_month_week column and the other has a date column.</p>
  <pre><code>df1&lt;-data.frame(id=c(1,1,1,2,2,2,2),
                 year_month_week=c(2022051,2022052,2022053,2022041,2022042,2022043,2022044),
                 points=c(65,58,47,21,25,27,43))
  
  df2&lt;-data.frame(id=c(1,1,1,2,2,2),
                  date=c(20220503,20220506,20220512,20220401,20220408,20220409),
                  temperature=c(36.1,36.3,36.6,34.3,34.9,35.3))
  </code></pre>
  <p>For df1, 2022051 means 1st week of May,2022. Likewise, 2022052 means 2nd week of May,2022. For df2,20220503 means May 3rd, 2022. What I want to do now is merge df1 and df2 with respect to year_month_week. In this case, 20220503 and 20220506 are 1st week of May,2022.If more than one date are in year_month_week, I will just include the first of them. Now, here's the different part. Even if there is no <code>date</code> inside <code>year_month_week</code>,just leave it <code>NA</code>. So my expected output has a same number of rows as <code>df1</code> which includes the column <code>year_month_week</code>.So my expected output is as follows:</p>
  <pre><code>df&lt;-data.frame(id=c(1,1,1,2,2,2,2),
                 year_month_week=c(2022051,2022052,2022053,2022041,2022042,2022043,2022044),
                 points=c(65,58,47,21,25,27,43),
                 temperature=c(36.1,36.6,NA,34.3,34.9,NA,NA))
  </code></pre>