title: Summarize based on time between
body: <p>I'm trying to summarize a data set based on the time between, within a group. Basically what I have is, like this example, a data set where students buy a course, the courses have levels : 1 till 5, every course is about 2 months and students can just follow the courses from 1 till 5. I want to analyze when students:</p>
  <ul>
  <li>drop out. So that would be, when they have not bought a new course after 2 months</li>
  <li>What the last course was, after they have not bought a course in 2 months</li>
  <li>and if they, after they stopped later decided to continue again</li>
  </ul>
  <p>and example of my data set is this:</p>
  <pre><code>&gt; data
  
  Student     Buy_Date      Course
  A           01-01-2019    Level 1
  A           01-03-2019    Level 2
  A           01-05-2019    Level 3
  A           01-07-2019    Level 4
  B           01-01-2019    Level 1
  B           01-03-2019    Level 2
  B           01-09-2019    Level 3
  </code></pre>
  <p>What I would like to have as a result is:</p>
  <pre><code>&gt; Data_Result
      Student     First_Buy    First_Course   Last_Course   Stopped_Date   Continued?     Course_Continued      
      A           01-01-2019   Level 1        Level 4       01-07-2019     No             NA
      B           01-01-2019   Level 1        Level 2       01-03-2019     Yes            Level 3
  </code></pre>
  <p>I have tried to search for options like <a href="https://www.geeksforgeeks.org/how-to-calculate-time-difference-with-previous-row-of-a-dataframe-by-group-in-r/" rel="nofollow noreferrer">this</a> but I'm not getting further then: ordering the row within group based on time and calculate the time between the previous. But I get stuck after that.. Could someone help me?</p>