Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master #69

Merged
merged 14 commits into from
Jan 8, 2018
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
more cleanup
  • Loading branch information
darya-akimova committed Dec 27, 2017
commit be9cb5c4a7d5235fd5252f498fd8d032cb30518c
80 changes: 62 additions & 18 deletions R/datawrangling/atc_codes_cleanup.rmd
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,73 @@ Both the level5 and the kegg columns may contain IDs that can be useful for conn

Technically, the level1-level4 columns contain potentially redundant information, but it may be useful for grouping in the future.


```{r}
unique(atc.codes.c$level1)
atc.codes.c <- atc.codes.c %>%
mutate(code = recode(
mutate(level5_code = str_sub(level5, 1, 7)) %>%
mutate(level5 = str_sub(level5, 9, -1)) %>%
select(level5_code, everything())
glimpse(atc.codes.c)
length(unique(atc.codes.c$level5_code))
nrow(atc.codes.c)
# a sign that some trimming needs to be done or drugs are used for multiple indications
atc.codes.c <- atc.codes.c %>%
mutate(level1_code = recode(
level1,
"alimentary tract and metabolism" = "a",
"blood and blood forming organs" = "b",
"cardiovascular system" = "c",
"dermatologicals" = "d",
"genito urinary system and sex hormones" = "g",
"systemic hormonal preparations, excl. sex hormones and insulins" = "h",
"antiinfectives for systemic use" = "j",
"antineoplastic and immunomodulating agents" = "l",
"musculo-skeletal system" = "m",
"nervous system" = "n",
"antiparasitic products, insecticides and repellents" = "p",
"respiratory system" = "r",
"sensory organs" = "s",
"various" = "v"
"alimentary tract and metabolism" = "A",
"blood and blood forming organs" = "B",
"cardiovascular system" = "C",
"dermatologicals" = "D",
"genito urinary system and sex hormones" = "G",
"systemic hormonal preparations, excl. sex hormones and insulins" = "H",
"antiinfectives for systemic use" = "J",
"antineoplastic and immunomodulating agents" = "L",
"musculo-skeletal system" = "M",
"nervous system" = "N",
"antiparasitic products, insecticides and repellents" = "P",
"respiratory system" = "R",
"sensory organs" = "S",
"various" = "V"
)
) %>%
select(level5:kegg, code, everything())
select(level5_code:kegg, level1_code, everything())
glimpse(atc.codes.c)
unique(atc.codes.c$level1_code)
# everything is recoded
```

Now to split off the second level through the fourth level codes and to convert the remaining strings to lowercase:

```{r}
atc.codes.c <- atc.codes.c %>%
mutate(level2_code = str_sub(level2, 1, 3),
level3_code = str_sub(level3, 1, 4),
level4_code = str_sub(level4, 1, 5))
glimpse(atc.codes.c)
unique(atc.codes.c$code)
atc.codes.c <- atc.codes.c %>%
mutate(level2 = str_to_lower(str_sub(level2, 5, -1)),
level3 = str_to_lower(str_sub(level3, 6, -1)),
level4 = str_to_lower(str_sub(level4, 7, -1))) %>%
select(level5_code:level1, level2_code, level2, level3_code, level3, level4_code, level4)
glimpse(atc.codes.c)
```

Happy with the structure of it for now. A bit of sanity checking before uploading the cleaned version to data.world:

```{r}
sapply(atc.codes.c, function(x) length(unique(x)))
```

Starting at the third level, there are more codes than descriptions. What's going on?

```{r}
mult.level3 <- atc.codes.c %>%
select(starts_with("level3")) %>%
unique() %>%
group_by(level3) %>%
summarize(tot = n()) %>%
filter(tot > 1)
test <- atc.codes.c %>%
filter(level3 %in% mult.level3$level3)
```