title: R data transformation
body: <p>I have an R data frame that looks like this:</p>
  
  <pre><code>z = as.data.frame(list(Col1=c("a","c","e","g"),Col2=c("b","d","f","h"),Col3=c("1,2,5","3,5,7","9,8","1")))
  &gt; z
    Col1 Col2  Col3
  1    a    b 1,2,5
  2    c    d 3,5,7
  3    e    f   9,8
  4    g    h     1
  </code></pre>
  
  <p>(The third column is a text column with comma-separated values.)  I would like to convert it to a data frame like this:</p>
  
  <pre><code>a    b    1
  a    b    2
  a    b    5
  c    d    3
  c    d    5
  c    d    7
  e    f    9 
  e    f    8
  g    h    1
  </code></pre>
  
  <p>Can anyone suggest a way to accomplish this using apply?  I'm close using the command below but it's not quite right.  Any suggestions on more efficient ways to do this would be appreciated as well...</p>
  
  <pre><code>&gt; apply(z,1,function(a){ids=strsplit(as.character(a[3]),",")[[1]];out&lt;-c();for(id in ids){out&lt;-rbind(out,c(a[1:2],id))};return(out)})
  [[1]]
       Col1 Col2    
  [1,] "a"  "b"  "1"
  [2,] "a"  "b"  "2"
  [3,] "a"  "b"  "5"
  
  [[2]]
       Col1 Col2    
  [1,] "c"  "d"  "3"
  [2,] "c"  "d"  "5"
  [3,] "c"  "d"  "7"
  
  [[3]]
       Col1 Col2    
  [1,] "e"  "f"  "9"
  [2,] "e"  "f"  "8"
  
  [[4]]
       Col1 Col2    
  [1,] "g"  "h"  "1"
  </code></pre>