Question: I have a dataset that contains 3-digit ICD-9 codes and I want to create a ICD9 description variable based on the 3 digit codes. Here is a code to replicate my dataset:

```
id=c(1:5);icdcode=c("786","401","780","300","V30");df=data.frame(id,icdcode)

```

I used the following code to create a new var "icd9.explain":

```
df$icd.explain=icd9ExplainShort(as.character(df$icdcode))

```

My resulting dataset looks like this:

```
> df
  id icdcode                                    icd.explain
1  1     786 Anxiety, dissociative and somatoform disorders
2  2     401 Anxiety, dissociative and somatoform disorders
3  3     780 Anxiety, dissociative and somatoform disorders
4  4     300 Anxiety, dissociative and somatoform disorders
5  5     V30 Anxiety, dissociative and somatoform disorders

```

Does anyone have an idea about how I can get the correct code explanations?

Thanks!!

Answer: 
`icd` (formerly `icd9` package author here. Just picked up on your question, which I realise is a while ago.

The package will guess whether you have short form Eg. 0100 or decimal form e.g. 010.0, so you can simplify this slightly. You also don't need to convert to `character` since it will already handle character or factors.

```
id=c(1:5)
icdcode <- c("786","401","780","300","V30")
df <- data.frame(id, icdcode, desc = icd::explain_code(icdcode))

```

There is also `explain_table` which grabs the short and long descriptions, and ICD chapter and sub-chapter for each code.
For anyone who might be experiencing this issue in the future, I was able to resolve my issue by using the lapply function:

```
 lapply(as.character(df$icdcode),function(x){icd9ExplainShort(x)})

```