title: Identify subsequent event for repeat IDs based on dates and initial event
body: <p>I am trying to determine repeat IDs based on date and an initial event. Below is a sample data set</p>
  
  <pre><code>
  +----+------------+-------------------------+
  | ID |    Date    | Investigation or Intake |
  +----+------------+-------------------------+
  |  1 | 1/1/2019   | Investigation           |
  |  2 | 1/2/2019   | Investigation           |
  |  3 | 1/3/2019   | Investigation           |
  |  4 | 1/4/2019   | Investigation           |
  |  1 | 1/2/2019   | Intake                  |
  |  2 | 12/31/2018 | Intake                  |
  | 3  | 1/5/2019   | Intake                  |
  +----+------------+-------------------------+
  
  </code></pre>
  
  <p>I want to write R codes to go through IDs from 1 to 4 (IDs that have investigations) and see if they have a subsequent intake (an intake that happens at a later date than the date of investigation). So the expected output looks like this:</p>
  
  <pre><code>
  +----+------------+-------------------------+------------+
  | ID |    Date    | Investigation or Intake | New Column |
  +----+------------+-------------------------+------------+
  |  1 | 1/1/2019   | Investigation           | Sub Intake |
  |  2 | 1/2/2019   | Investigation           | None       |
  |  3 | 1/3/2019   | Investigation           | Sub Intake |
  |  4 | 1/4/2019   | Investigation           | None       |
  |  1 | 1/2/2019   | Intake                  |            |
  |  2 | 12/31/2018 | Intake                  |            |
  | 3  | 1/5/2019   | Intake                  |            |
  +----+------------+-------------------------+------------+
  
  </code></pre>
  
  <p>What will the code look like to solve this? I am guessing it will be some loop function?</p>
  
  <p>Thanks!</p>