R: SAS (if/then statement )in R

后端 未结 4 1374
遥遥无期
遥遥无期 2021-01-16 17:28

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

4条回答
  •  攒了一身酷
    2021-01-16 18:03

    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
    

提交回复
热议问题