title: Dynamically Generate List From Dataframe Elements (dynamic categories)
body: <p>folks-</p>
  <p>I am trying to generate a <code>list</code> in R where each element of the <code>list</code> represents a disease category, and within each element is a vector of corresponding patient ids. In order to do this, I would like to utilize relationships defined in an existing <code>data.frame</code>.</p>
  <pre><code>diseaseTbl &lt;- data.frame(PatientId = c(1,2,3,4,5,6,2,3,4,1,2,3,7,8,9,10),
                          DiseaseCat = c(rep('Obesity',6),rep('Diabetes',3),rep('Hypertension',7)))
  </code></pre>
  <p>Here's my approach to generate the <code>list</code> I'm looking for- which is admittedly not ideal:</p>
  <pre><code>myList = list(
                    Obesity=diseaseTbl[which(diseaseTbl$DiseaseCat == 'Obesity'),]$PatientId,
                    Diabetes=diseaseTbl[which(diseaseTbl$DiseaseCat == 'Diabetes'),]$PatientId,
                    Hypertension=diseaseTbl[which(diseaseTbl$DiseaseCat == 'Hypertension'),]$PatientId
              )
  </code></pre>
  <p>This is a small scale example- whereas my live data is filled with 30+ disease categories. I would like a way to dynamically generate this <code>list</code> so that I can adapt dynamically to changing disease categories (add/remove). Is there a more elegant solution out there? I assume that I will be embarrassed by how easy this is for somebody to figure out. Thank you!</p>