A simple function to simulate ICD-10 and ICD-9 diagnostic codes at random.
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
, andICD9_2015
; defaults toICD10_2011
. See icd10_2009, icd10_2011, and icd9_2015 for further information on the different schemes.
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