generated from nhsengland/analyticsunit-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
endoscopy_rooms.R
40 lines (32 loc) · 2.03 KB
/
endoscopy_rooms.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# Create table for number of endoscopy rooms (excluding planned)
library(dplyr)
# Bring in data
endoscopy_stocktake <- read_excel("C:/Users/martin.bloyce/OneDrive - NHS England/Restricted Library/SE/Analysis/Diagnostics/Endoscopy Stocktake/Endoscopy Stocktake Database with pivot table.xlsx",
sheet = "Backing Data", skip = 2)
# Rename columns for ease
colnames(endoscopy_stocktake) <- c('ICB', 'Trust', 'Directorate', 'UnitName', 'QuestionKey','Question', 'Value', 'ValueType', 'SetResponseAnswer', 'FreeText', 'blank1', 'blank2', 'blank3')
# Create table at region level
constraints_rooms_region <- endoscopy_stocktake %>%
subset(.,
Question == 'How many endoscopy rooms are in use at this unit? include any that are only used from time to time') %>%
summarise(sum(as.numeric(Value)))
constraints_rooms_region$Loc <- 'SE Region'
constraints_rooms_region <- constraints_rooms_region[,c("Loc", "sum(as.numeric(Value))")]
colnames(constraints_rooms_region) <- c('Loc', 'Value')
# Create table at ICB level
constraints_rooms_ICB <- endoscopy_stocktake %>%
subset(.,
Question == 'How many endoscopy rooms are in use at this unit? include any that are only used from time to time') %>%
group_by(ICB) %>%
summarise(sum(as.numeric(Value)))
colnames(constraints_rooms_ICB) <- c('Loc', 'Value')
# Create table at unit level ## could rename 'trust' to 'unit? ##
constraints_rooms_trust <- endoscopy_stocktake %>%
subset(.,
Question == 'How many endoscopy rooms are in use at this unit? include any that are only used from time to time') %>%
select(c(UnitName, Value))
colnames(constraints_rooms_trust) <- c('Loc', 'Value')
# Combine tables to create a master
constraints_rooms_master <- rbind(constraints_rooms_region, constraints_rooms_ICB, constraints_rooms_trust)
# Drop not needed objects
rm(constraints_rooms_ICB, constraints_rooms_region, constraints_rooms_trust)