title: Calculating Occupancy in hospital from dates with time.
body: <p>I am looking to calculate occupancy in emergency department (ED) with tidyverse. Occupancy is understood here in this particular problem as Admitted but did not leave the hospital within the same hour they were admitted. A clearer example would be: if I came at ED at 12:00:00 and did not leave within the hour I was admitted, then I am occupying the bospital. So for this I need to create a new column Occupancy. (A little insight to give - I want to plot occupancy by hour of the day. Yet I know how to plot this, but do not know how to calculate occupancy. Thus no need for you to be bogged down on this issue as I am giving you an insight of my project). What I need though is to learn how to calculate occupancy from the table I have bellow. Please do help. </p>
  
  <p>I have ID, Admission = Adm and Disc = Discharges. </p>
  
  <pre><code>ID = c(101, 102,103, 104, 105, 106, 107)
  
  Adm = as.POSIXct(c("2012-01-12 00:52:00", "2012-01-12 00:55:00", "2012-02-12 
                      01:35:00", "2012-02-12 03:24:00", "2012-02-12 04:24:00", 
                     "2012-02-12 05:24:00", "2012-02-12 05:28:00"))
  
  Disc = as.POSIXct(c("2012-01-12 02:00:00", "2012-01-12 02:59:00", "2012-01-12 
                       03:01:00", "2012-01-12 05:01:00", "2012-01-12 06:01:00", 
                      "2012-01-12 08:01:00", "2012-01-12 08:01:00"))
  
  df = data.frame(ID, Adm, Disc)
  </code></pre>
  
  <p>I have extracted the hour from the Admission. So that I can use the new column for calculating the occupancy - understood at the problem at hand as Admitted but were not discharged within the hour the patients were admitted. To remind you, I want to do this with tidyverse library</p>
  
  <pre><code>df_hour &lt;- df %&gt;%
    mutate(Hour_Adm = lubridate::hour(as.POSIXct(Adm, "%Y%m%d %H:%M:%S"))) 
  </code></pre>
  
  <p>Any help is very much appreciated. Thank you. </p>