title: Splitting Factors in dataframes in R
body: <p>Here is an example dataframe:</p>
  
  <pre><code>x &lt;- list(a = c("1", "2", "2, 3"), b = c("2", "3", "5, 6"), id = c("a1", "a2", "a3"))
  x1 &lt;- as.data.frame(x)
  
  str(x1)
  
  'data.frame':   3 obs. of  3 variables:
  $ a : Factor w/ 3 levels "1","2","2, 3": 1 2 3
  $ b : Factor w/ 3 levels "2","3","5, 6": 1 2 3
  $ id: Factor w/ 3 levels "a1","a2","a3": 1 2 3
  
  x1
  
  a     b     id
  1     2     a1
  2     3     a2
  2, 3  5, 6  a3
  </code></pre>
  
  <p>you see that x1$a and x1$b have two values on position: "2, 3" and "5, 6", but on x1$id there is just one value. </p>
  
  <p>My question is if you know a way to split the two values, make a forth value with the same $id value. So that it looks like this: </p>
  
  <pre><code>str(x1)
  
  'data.frame':   4 obs. of  3 variables:
  $ a : Factor w/ 4 levels "1","2","2","3": 1 2 3 4
  $ b : Factor w/ 4 levels "2","3","5","6": 1 2 3 4
  $ id: Factor w/ 3 levels "a1","a2","a3", "a3": 1 2 3
  
  x1
  
  a     b     id
  1     2     a1
  2     3     a2
  2     5     a3
  3     6     a3
  </code></pre>
  
  <p>Edit: $a and $b always have the same amount of variables</p>
  
  <p>Edit2: Thanks to  Ronak Shah it worked</p>
  
  <pre><code>-&gt; cSplit(x, c("a", "b"), ",", "long")
  </code></pre>