add_phecode_levels: Add phecode levels to dataframe

Description Usage Arguments Value Examples

View source: R/add_phecode_levels.R

Description

Takes a dataframe with a phecode column and replaces it with the hierarchichal levels of the phecodes as columns code_l1, code_l2 and code_l3.

Usage

1
2
3
4
5
add_phecode_levels(
  phecode_data,
  phecode_column = phecode,
  remove_phecode_column = TRUE
)

Arguments

phecode_data

Dataframe with a column encoding phecodes (make sure codes are normalized via normalize_phecodes).

phecode_column

Unquoted name of the column containing phecodes

remove_phecode_column

Should the original phecode column be kept in the data?

Value

Dataframe with phecode levels added as three integer columns

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
patient_data <- dplyr::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,
)

# Default removes original phecode column
add_phecode_levels(patient_data, code)

# Can keep original column as well
add_phecode_levels(patient_data, code, remove_phecode_column = FALSE)

nstrayer/phewasHelper documentation built on April 2, 2020, 5:06 a.m.