title: Time differences for multiple entries for same ID in R
body: <p>For each ID that is the same, I would like to add an end time and then calculate the time differences between each entry for that user ID.</p>
  <p>This is the code I have so far:</p>
  <p><code>user &lt;- user %&gt;% group_by(user$userdata.user_id) %&gt;% arrange(user$hours) %&gt;% mutate(time.interval= user$hours - lag(user$hours, default = first(user$hours))) %&gt;% mutate(time.interval = round(time.interval/86400, digits = 2))</code></p>
  <p>I was trying to use the diff time() function, however since I am trying to calculate the time difference with a preset end date  ('02-20-2020' = 7), I am unable to attain the following results:</p>
  <p><code>id      hours      time.decimal    time.interval</code></p>
  <p><code>123     03:32:12    1.200           3.3 (4.5 - 1.2)</code></p>
  <p><code>123     12:37:56    4.500           2.5 (7 - 4.5)</code></p>
  <p><code>140     09:46:33    6.300           0.7 (7 - 6.3)</code></p>
  <p>**Note: the above is an example of what I want to achieve. 7 in the time interval column is the time decimal version of the given end date.</p>
  <p>Any help would be greatly appreciated.</p>