title: Find repeated user ID in future timeframe (in R)
body: <p>I have a table for user IDs and account logins that runs from 2017-01-01 to 2018-05-01. It's infrequent, so I want to see if they log in +/- 45 days of the same date each year (in code below I used 320/410, I'll finesse the dates later unless it's necessary for this operation).</p>
  
  <pre><code>loginID     userID     date
  1           a          2017-01-03
  2           b          2017-01-12
  3           c          2017-01-14
  4           d          2017-01-19
  5           d          2017-10-18
  6           a          2017-11-30
  7           b          2017-12-09
  8           c          2017-12-17
  9           a          2017-12-30
  10          b          2018-01-15
  </code></pre>
  
  <p>I'm trying to write a loop where the table references itself. The best I have (not working but have gone through several attempts) is:</p>
  
  <pre><code>for (row in 1:nrow(df)){
      target &lt;- subset(df, date &lt; (row$date+410))
      target &lt;- subset(target, date &gt; (row$date+320))
      target &lt;- target$userID
      df$ninety &lt;- row$userID %in% target
  }
  </code></pre>
  
  <p>The the results I'm looking for are:</p>
  
  <pre><code>loginID     userID     date         repeat_oneyr
  1           a          2017-01-03   TRUE
  2           b          2017-01-12   TRUE
  3           c          2017-01-14   TRUE
  4           d          2017-01-19   FALSE
  5           d          2017-10-18   FALSE
  6           a          2017-11-30   FALSE
  7           b          2017-12-09   FALSE
  8           c          2017-12-17   FALSE
  9           a          2017-12-30   FALSE
  10          b          2018-01-15   FALSE
  </code></pre>
  
  <p>(Reason everything after/including 2017-10-18 is FALSE is because we don't have the login data to show whether or not they logged in between 320 and 410 days from then).</p>
  
  <p>I know (from other SO questions/answers) that if I can get a TRUE/FALSE iterated over every loginID, I can use <code>match()</code> to join the data frames, so I'm not worried about that part - it's getting the TRUE/FALSE in the first place.</p>
  
  <p>Any advice welcome/appreciated.</p>