-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path09 String matches using IFELSE to create labels.R
More file actions
27 lines (25 loc) · 1.2 KB
/
09 String matches using IFELSE to create labels.R
File metadata and controls
27 lines (25 loc) · 1.2 KB
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
# 3 Split main dataset by organisaion types (CCG, TRUST, STP)
#
# The grepl() stands for “grep logical”.
# In R it is a built-in function that searches for matches
# of a string or string vector. The grepl() method takes a pattern (we define that string pattern in our search)
# and data and returns TRUE if a string contains the pattern, otherwise FALSE.
# We use ifelse() nested conditions to flag each sting match provided by grepl function
# and assign it the corresponding organisation label description
Torgrc <- IMPRDASH %>%
select(OrgName) %>%
mutate(
ORGTYPE = ifelse(grepl('CCG',OrgName),'CCG',
(ifelse(grepl('Trust',OrgName),'TRUST',
(ifelse(grepl('STP',OrgName),'STP',0)))))
)
IMPRDASI <-IMPRDASH %>%
select(OrgName,OrgType,Measure,SubCompartment,Value,ReportingDate,Frequency,Quarter,STPCode) %>%
mutate(
ORGTYPE = ifelse(grepl('CCG',OrgName),'CCG',
(ifelse(grepl('Trust',OrgName),'TRUST',
(ifelse(grepl('STP',OrgName),'STP',0)))))
)
IMP_STP <- IMPRDASI %>% filter(ORGTYPE=='STP')
IMP_CCG <- IMPRDASI %>% filter(ORGTYPE=='CCG')
IMP_TRUST <- IMPRDASI %>% filter(ORGTYPE=='TRUST')