title: Split data frame string column into multiple columns
body: <p>I'd like to take data of the form</p>
  
  <pre><code>before = data.frame(attr = c(1,30,4,6), type=c('foo_and_bar','foo_and_bar_2'))
    attr          type
  1    1   foo_and_bar
  2   30 foo_and_bar_2
  3    4   foo_and_bar
  4    6 foo_and_bar_2
  </code></pre>
  
  <p>and use <code>split()</code> on the column "<code>type</code>" from above to get something like this:</p>
  
  <pre><code>  attr type_1 type_2
  1    1    foo    bar
  2   30    foo  bar_2
  3    4    foo    bar
  4    6    foo  bar_2
  </code></pre>
  
  <p>I came up with something unbelievably complex involving some form of <code>apply</code> that worked, but I've since misplaced that. It seemed far too complicated to be the best way. I can use <code>strsplit</code> as below, but then unclear how to get that back into 2 columns in the data frame.</p>
  
  <pre><code>&gt; strsplit(as.character(before$type),'_and_')
  [[1]]
  [1] "foo" "bar"
  
  [[2]]
  [1] "foo"   "bar_2"
  
  [[3]]
  [1] "foo" "bar"
  
  [[4]]
  [1] "foo"   "bar_2"
  </code></pre>
  
  <p>Thanks for any pointers. I've not quite groked R lists just yet.</p>