Skip to content

Instantly share code, notes, and snippets.

@Dpananos
Created June 6, 2019 01:29
Show Gist options
  • Save Dpananos/bf7ac00816a05e8d518400552f7cfcde to your computer and use it in GitHub Desktop.
Save Dpananos/bf7ac00816a05e8d518400552f7cfcde to your computer and use it in GitHub Desktop.
Length of stay in days
library(tidyverse)
library(lubridate)
#Make fake data
dates2019 <- seq(ymd('2019-01-01'), ymd('2019-12-31'), by ='1 week')
dates2020 <- seq(ymd('2020-01-01'), ymd('2020-12-31'), by ='1 week')
admission <- sample(dates2019, size = 10)
discharge <- sample(dates2020, size = 10)
hospital_stays<-tibble(admission = admission, discharge = discharge)
#Calciulate duration in days
hospital_stays %>%
mutate(len_of_stay = as.numeric(discharge - admission, unit = 'days'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment