Takes phecodes that have been coded without rollup - E.g. existance of code 008.10 does not imply the existance of 008.00 - and produces a rolledup version of the dataset. Works with plain patient-phecode pairs and also with patient-code-count triplets.
rollup_phecode_counts( patient_code_counts, patient_col = patient, phecode_col = phecode, count_col = counts )
patient_code_counts | Data containing patient ids, phecodes, and counts of those phecodes. |
---|---|
patient_col | Unquoted name of the column containing patient ids in
passed |
phecode_col | Unquoted name of the column containing phecodes in passed dataframe. |
count_col | Unquoted name of the column containing counts of phecodes in passed dataframe. |
Dataframe in same format as passed patient_code_counts
with code
counts rolled up. This will most likely be longer than the original dataset
because of the addition of potentially previously ommitted codes.
library(dplyr) patient_data <- tribble( ~patient, ~code, ~counts, 1, "250.23", 7, 1, "250.25", 4, 1, "696.42", 1, 1, "555.21", 4, 2, "401.22", 6, 2, "204.21", 5, 2, "735.22", 4, 2, "751.11", 2, ) # Rolls up counts for codes if they are present patient_data %>% rollup_phecode_counts(patient_col = patient, phecode_col = code, count_col = counts)#> # A tibble: 22 x 3 #> code patient counts #> <chr> <dbl> <dbl> #> 1 250.00 1 11 #> 2 250.20 1 11 #> 3 250.23 1 7 #> 4 250.25 1 4 #> 5 555.00 1 4 #> 6 555.20 1 4 #> 7 555.21 1 4 #> 8 696.00 1 1 #> 9 696.40 1 1 #> 10 696.42 1 1 #> # … with 12 more rows