title: Merging overlapping dataframes in R
body: <p>Okay, so I have two different data frames (df1 and df2) which, to simplify it, have an ID, a date, and the score on a test. In each data frame the person (ID) have taken the test on multiple dates. When looking between the two data frames, some of the people are listed in df1 but not in df2, and vice versa, but some are listed in both and they can overlap differently. </p>
  
  <p>I want to combine all the data into one frame, but the tricky part is if any of the IDs and scores from df1 and df2 are within 7 days (I can do this with a subtracted dates column), I want to combine that row.</p>
  
  <p>In essence, for every ID there will be one row with both scores written separately if taken within 7 days, and if not it will make two separate rows, one with score from df1 and one from df2 along with all the other scores that might not be listed in both.</p>
  
  <p>EX:</p>
  
  <p><strong>df1</strong></p>
  
  <pre><code>ID Date1(yyyymmdd) Score1
  1  20140512        50
  1  20140501        30
  1  20140703        50
  1  20140805        20
  3  20140522        70
  3  20140530        10
  </code></pre>
  
  <p><strong>df2</strong></p>
  
  <pre><code>ID Date2(yyyymmdd) Score2
  1  20140530        40
  1  20140622        20
  1  20140702        10
  1  20140820        60
  2  20140522        30
  2  20140530        80
  </code></pre>
  
  <p><strong>Wanted_df</strong></p>
  
  <pre><code>ID Date1(yyyymmdd) Score1 Date2(yyyymmdd) Score2
  1  20140512        50                     
  1  20140501        30
  1  20140703        50     20140702        10
  1  20140805        20
  1                         20140530        40
  1                         20140622        20
  1                         20140820        60
  3  20140522        70
  3  20140530        10
  2                         20140522        30
  2                         20140530        80
  </code></pre>