Skip to content

Instantly share code, notes, and snippets.

View gabrielburcea's full-sized avatar

GabrielBurcea gabrielburcea

View GitHub Profile
hashed_id <- function(x, salt){
y <- paste(x, salt)
y <- sapply(y, function(X) digest(X, algo = "sha1"))
as.character(y)
}
data$PseudoID <- hashed_id(data$PseudoID, "somesalt1234")
data$Postcode.Sector <- hashed_id(data$Postcode.Sector, "somesalt1234")
plt_month <-ggplot(plt_wkd_mean, aes(x = Weekday, y = Average))
plt_month + geom_bar(stat = "identity", position = "identity", alpha = 0.5, width = 0.4, fill= "red") +
#geom_line()+
#geom_point()+
scale_y_continuous(expand = c(0, 0), limits = c(0, 200)) +
xlim("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun") +
labs(title = "Chelsea: Montly Occupancy, 1st of Jan to 31st of Dec 2013",
subtitle = "Average Occupancy (medical patients) by Days of the Week.
Note: results are intended for management information only",
y = "Average - Occupancy", x = "Day of the Week", caption = "CLAHRC - NIHR") + #caption = "Source: Imperial Data Dive - Hackaton") +
@gabrielburcea
gabrielburcea / gist:eb3f98d756d72683b35f777ecc98613c
Last active July 26, 2018 14:18
Slide 14 - daily emergency access performance, Jan to July 2015
library(tidyverse)
library(lubridate)
data <- read.csv("df.csv", header = TRUE)
data$X <- NULL
#######################################################
# Code that converts all the columns names to lowercase
@gabrielburcea
gabrielburcea / gist:7be162b7253c3be2137baf63cb66786f
Last active July 26, 2018 14:17
Slide 22 - Occupancy vs. Arrivals - hospital
###################################################
# Arrivals vs Occupancy - #####################
# for one month - from 01-03-2015 to 27-04-2015 ###
###################################################
##################################################
# loading the libraries
##################################################
library(tidyverse)
@gabrielburcea
gabrielburcea / gist:35cadcbf40cfdc55b3e969621cbbd7a7
Last active July 26, 2018 14:16
A&E - arrivals - March to April, 27th, 2013
###################################################
# A&E - arrivals - March to April, 27th, 2013 ##
###################################################
#######################
#reading the data #####
#######################
data <- read.csv("df.csv", header = TRUE)
@gabrielburcea
gabrielburcea / gist:5a8e274af6650e9027b904d5c42ac028
Last active July 26, 2018 14:14
slide 46 - Admissions and Discharges
##############################
# Admissions and Discharges
##############################
####################
#reading the data ##
####################
data <- read.csv("df.csv", header = TRUE)
head(data, 10)
@gabrielburcea
gabrielburcea / gist:06a7bd71e45f864a945e0c654aabba02
Last active July 26, 2018 14:12
slide 13 Readmission in 7 days
####################################
# Readmission_7days ################
####################################
library(tidyverse)
library(lubridate)
data <- read.csv("/df.csv")
data$X <- NULL
four_hrs_perf_data_clean <- function(df) {
colname_ct <- function(df, colname){
df[,colname] = as.POSIXct(df[,colname])
df
}
df %>%
dplyr::select("PAT_CODE", "START_DATETIME", "END_DATETIME", "WARD_CODE", "episode.order", "spell.number") %>%
@gabrielburcea
gabrielburcea / gist:daa4f5d23589ea25f551076894fb551f
Last active August 16, 2018 09:26
Creating a new variable out of two - case_when ; group_indices - tidyerse
# Creating a new variable out of two
data_indices <- df_subs %>%
mutate(sex_patient_class = case_when(
sex == "Female" & patient.class == "Not_Admitted" ~ "female_not_admitted",
sex == "Female" & patient.class == "ORDINARY ADMISSION" ~ "female_admitted",
sex == "Male" & patient.class == "Not_Admitted" ~ "male_not_admitted",
sex == "Male" & patient.class == "ORDINARY ADMISSION" ~ "male_admitted"
))
@gabrielburcea
gabrielburcea / gist:3ad0d1c48d397f55ff8b59f5d715d679
Created August 16, 2018 16:30
Replace NA values with a factor level, use multiple conditions with filter function
df_subset <- df %>%
filter(spell.type == "Emergency" & sex != "Not Specified",
end_datetime >= "2012-09-29" & end_datetime <= "2013-09-29") %>%
mutate(as.Date(end_datetime)) %>%
replace_na(list(patient.class = "Not_Admitted")) %>%
select(pat_code, end_datetime, age_band, sex, patient.class, spell.type)