generated from opensafely/research-template
/
00_trim_snomed_codelist.r
67 lines (51 loc) · 2.42 KB
/
00_trim_snomed_codelist.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
## splits the PRIMIS, CTV3 and SNOMED ethnicity codelists into 5 and 16 group categories
library('tidyverse')
library('sf')
# # import data
df_input <- read_csv(here::here("codelists","opensafely-ethnicity.csv"))
group_split<-df_input %>%
group_split(Grouping_6)
ethnicities<-c('white','mixed','asian','black','other')
for (i in 1:5){
list<-group_split[i][[1]] %>% select(Code,Description)
write_csv(list,here::here("codelists",paste0("ethnicity_5_",ethnicities[i],".csv")))
}
df_input <- read_csv(here::here("codelists","opensafely-ethnicity-snomed-0removed.csv")) %>%
filter(Grouping_6!=0)
group_split<-df_input %>%
group_split(Grouping_6)
for (i in 1:5){
list<-group_split[i][[1]] %>% select(snomedcode,Ethnicity) %>% rename(Code = snomedcode)
write_csv(list,here::here("codelists",paste0("ethnicity_new_5_",ethnicities[i],".csv")))
}
df_input <- read_csv(here::here("codelists","primis-covid19-vacc-uptake-eth2001.csv"))
group_split<-df_input %>%
group_split(grouping_6_id)
for (i in 1:5){
list<-group_split[i][[1]] %>% select(code,term) %>% rename(Code=code)
write_csv(list,here::here("codelists",paste0("ethnicity_primis_5_",ethnicities[i],".csv")))
}
### group 16
df_input <- read_csv(here::here("codelists","opensafely-ethnicity.csv"))
group_split<-df_input %>%
group_split(Grouping_16)
ethnicities_16<-c('White_British','White_Irish','Other_White','White_and_Black_Caribbean','White_and_Black_African','White_and_Asian','Other_Mixed','Indian','Pakistani','Bangladeshi','Other_Asian','Caribbean','African','Other_Black','Chinese','Any_other_ethnic_group')
for (i in 1:16){
list<-group_split[i][[1]] %>% select(Code,Description)
write_csv(list,here::here("codelists",paste0("ethnicity_16_",ethnicities_16[i],".csv")))
}
df_input <- read_csv(here::here("codelists","opensafely-ethnicity-snomed-0removed.csv")) %>%
filter(Grouping_16!=0)
group_split<-df_input %>%
group_split(Grouping_16)
for (i in 1:16){
list<-group_split[i][[1]] %>% select(snomedcode,Ethnicity) %>% rename(Code = snomedcode)
write_csv(list,here::here("codelists",paste0("ethnicity_new_16_",ethnicities_16[i],".csv")))
}
df_input <- read_csv(here::here("codelists","primis-covid19-vacc-uptake-eth2001.csv"))
group_split<-df_input %>%
group_split(grouping_16_id)
for (i in 1:16){
list<-group_split[i][[1]] %>% select(code,term) %>% rename(Code=code)
write_csv(list,here::here("codelists",paste0("ethnicity_primis_16_",ethnicities_16[i],".csv")))
}