Skip to contents

A simple function to simulate ICD-10 and ICD-9 diagnostic codes at random.

Usage

sample_diag(n = 1, version = "ICD10_2011")

Arguments

n

Number of ICD codes to simulate.

version

The version of the ICD coding scheme to use. Possible choices are ICD10_2009, ICD10_2011, and ICD9_2015; defaults to ICD10_2011. See icd10_2009, icd10_2011, and icd9_2015 for further information on the different schemes.

Value

A vector of n ICD diagnostic codes.

Examples

# Simulate 10 ICD-10 codes
sample_diag(10)
#>  [1] "D682" "R454" "G308" "R90"  "N350" "S064" "V435" "V795" "M356" "R073"

# Simulate a tidy dataset with 15 individuals and 200 rows
set.seed(1)
x <- data.frame(
  id = sample(1:15, size = 200, replace = TRUE),
  code = sample_diag(n = 200),
  stringsAsFactors = FALSE
)
head(x)
#>   id code
#> 1  9  P23
#> 2  4 B942
#> 3  7 K764
#> 4  1 I950
#> 5  2 V549
#> 6 13  N90