title: fast subsetting in R
body: <p>I've got a dataframe dat of size 30000 x 50. I also have a separate list that contains points to groupings of rows from this dataframe, e.g.,</p>
  
  <pre><code>rows &lt;- list(c("34", "36", "39"), c("45", "46"))
  </code></pre>
  
  <p>This says that dataframe rows with rownames (not numeric row indeces, but character rownames(dat)) "34", "36", "39" constitute one grouping, and "45", "46" constitute another grouping.</p>
  
  <p>Now I want to pull out the groupings from the dataframe into a parallel list, but my code (below) is really, really slow. How can I speed it up?</p>
  
  <pre><code>&gt; system.time(lapply(rows, function(r) {dat[r, ]}))
     user  system elapsed 
   246.09    0.01  247.23 
  </code></pre>
  
  <p>That's on a very fast computer, R 2.14.1 x64.</p>