I was working previously with SAS and then decided to shift to R for academic requirements reasons. My data (healthdemo) are health data containing some health diagnostic co
I suppose the problem is du to icd_num
not being numeric.
Use the following command to create this variable:
healthdemo$icd_num <- as.numeric(substr(healthdemo$ICDCODE, 2,
nchar(healthdemo$ICDCODE)))
(If you want to get rid of the numbers after the .
, replace as.numeric
with as.integer
.)
Then your first approach should work:
healthdemo$cvd[healthdemo$icd_char == 'I' &
01 <= healthdemo$icd_num &
healthdemo$icd_num < 52 ] <- 1