title: Convert named vector to list in R
body: <p>Suppose I have the following named numeric vector:</p>
  
  <pre><code>a &lt;- 1:8
  names(a) &lt;- rep(c('I', 'II'), each = 4)
  </code></pre>
  
  <p>How can I convert this vector to a list of length 2 (shown below)?</p>
  
  <pre><code>a.list
  # $I
  # [1] 1 2 3 4
  # $II
  # [1] 5 6 7 8
  </code></pre>
  
  <p>Note that <code>as.list(a)</code> is not what I'm looking for.
  My very unsatisfying (and slow for large vectors) solution is:</p>
  
  <pre><code>names.uniq &lt;- unique(names(a))
  a.list &lt;- setNames(vector('list', length(names.uniq)), names.uniq)
  for(i in 1:length(names.uniq)) {
    names.i &lt;- names.uniq[i]
    a.i &lt;- a[names(a)==names.i]
    a.list[[names.i]] &lt;- unname(a.i)
  }
  </code></pre>
  
  <p>Thank you in advance for your help,
  Devin</p>