title: how to convert dataframe to list in R by id?
body: <p>I've been struggling whole evening to figure out how to do this in R.</p>
  
  <p>Basically I have a dataset like the following:</p>
  
  <pre><code>id&lt;-c(1,1,1,2,2,3,3,3,3)
  label&lt;-c('a', 'b', 'c', 'b', 'd', 'a', 'c', 'd', 'e')
  mydata&lt;-as.data.frame(cbind(id, label))
  mydata$id&lt;-as.integer(as.character(mydata$id))
  mydata$label&lt;-as.character(mydata$label)
  mydata
    id label
  1  1     a
  2  1     b
  3  1     c
  4  2     b
  5  2     d
  6  3     a
  7  3     c
  8  3     d
  9  3     e
  </code></pre>
  
  <p>I want to transform mydata into mylist to look like the following:</p>
  
  <pre><code>mylist&lt;-list()
  mylist[[1]]&lt;-c('a', 'b', 'c')
  mylist[[2]]&lt;-c( 'b', 'd')
  mylist[[3]]&lt;-c( 'a', 'c', 'd', 'e')
  mylist
  [[1]]
  [1] "a" "b" "c"
  
  [[2]]
  [1] "b" "d"
  
  [[3]]
  [1] "a" "c" "d" "e"
  </code></pre>
  
  <p>So, how do I go form mydata to mylist?</p>
  
  <p>NOTE: my actual dataframe has ~2 million rows.</p>
  
  <p>[background: I'm working on a multi-label classification problem and would need to calculate F1, precision and recall and as the no. labels are variable I thought I could chuck all of them into a big list and do the comparison that way]</p>