title: list of named lists to data.frame
body: <p>I have a list of named lists of the following form from a JSON object: </p>
  
  <pre><code>my_list = list(list(a = 10, b = "blah"), 
                 list(a = 15, b = "stuff"))
  </code></pre>
  
  <p>Each element of the outer list is a named list and I want to convert it to a data.frame of the following form with the column names intact:</p>
  
  <pre><code>a   b 
  10  "blah" 
  15  "stuff"
  </code></pre>
  
  <p>On the surface, I can achieve this by doing <code>to_df = data.frame(do.call(rbind, my_list))</code>.</p>
  
  <p>However, if I were to try to extract an individual column using <code>to_df$a</code> or <code>to_df[,1]</code> I would get a list instead of a vector as normally expected from a data.frame:</p>
  
  <pre><code>&gt; to_df[,1]
  [[1]]
  [1] 10
  
  [[2]]
  [1] 15
  </code></pre>
  
  <p>Instead of:</p>
  
  <pre><code>&gt; to_df[,1]
  [1] 10 15
  </code></pre>
  
  <p>An old post on the R mailing list suggested the following solution: <code>to_df = as.data.frame(t(sapply(my_list, rbind)))</code>.  But not only does this not transfer over the column names, it still has the same issue of returning a list instead of a vector when looking at individual columns using <code>to_df[,1]</code>.</p>
  
  <p>What's the best way to achieve this?  Is there a <code>dplyr</code> way?</p>
  
  <p>EDIT: Thanks for all the solutions, it appears the trick is to <code>lapply</code> and transform each element of the list to a <code>data.frame</code> and then bind them together using dplyr or <code>do.call</code>.  Alternatively, <code>data.table</code> does most of the work with a single call to <code>rbindlist</code>.</p>