Error: unsupported use of matrix or array for column indexing
<p>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. </p>

<p>For example patient 1 has "chd" only, therefore only that will be displayed as TRUE</p>

<blockquote>
  <p>comorbid_names
   [1] "chd"                         "heart_failure"               "stroke"<br>
   [4] "hypertension"                "diabetes"                    "copd"<br>
   [7] "epilepsy"                    "hypothyroidism"              "cancer"<br>
  [10] "asthma"                      "ckd_stage3"                  "ckd_stage4"<br>
  [13] "ckd_stage5"                  "atrial_fibrilation"          "learning_disability"<br>
  [16] "peripheral_arterial_disease" "osteoporosis"<br>
  class(comorbid_names)
  [1] "character"</p>
</blockquote>

<p>comorbidities &lt;- names(p[, comorbid_names][p[, comorbid_names] == 1])</p>

<p>At this point I get this error</p>

<p>Error: Unsupported use of matrix or array for column indexing</p>

<p>I am not entirely sure why, but I think it's to do with comorbid_names being character</p>

<p>Does anyone have an advice?</p>