Error: unsupported use of matrix or array for column indexing

I have a list of variables name “comorbid_names”. And I want to select people who have those comorbidities in “comorbidities”. However, I want to select the variable names if they are true.

For example patient 1 has “chd” only, therefore only that will be displayed as TRUE

comorbid_names [1] “chd” “heart_failure” “stroke”
[4] “hypertension” “diabetes” “copd”
[7] “epilepsy” “hypothyroidism” “cancer”
[10] “asthma” “ckd_stage3” “ckd_stage4”
[13] “ckd_stage5” “atrial_fibrilation” “learning_disability”
[16] “peripheral_arterial_disease” “osteoporosis”
class(comorbid_names) [1] “character”

comorbidities <- names(p[, comorbid_names][p[, comorbid_names] == 1])

At this point I get this error

Error: Unsupported use of matrix or array for column indexing

I am not entirely sure why, but I think it’s to do with comorbid_names being character

Does anyone have an advice?

Leave a Comment