title: Splitting one column into multiple columns
body: <p>I have a huge dataset in which there is one column including several values for each subject (row). Here is a simplified sample dataframe:</p>
  
  <pre><code>data &lt;- data.frame(subject = c(1:8), sex = c(1, 2, 2, 1, 2, 1, 1, 2), 
                age = c(35, 29, 31, 46, 64, 57, 49, 58), 
                v1 = c("2", "0", "3,5", "2 1", "A,4", "B,1,C", "A and B,3", "5, 6 A or C"))
  
  &gt; data
    subject sex age          v1
  1       1   1  35           2
  2       2   2  29           0
  3       3   2  31         3,5  # separated by a comma
  4       4   1  46         2 1  # separated by a blank space
  5       5   2  64         A,4
  6       6   1  57       B,1,C
  7       7   1  49   A and B,3
  8       8   2  58 5, 6 A or C
  </code></pre>
  
  <p>I first want to remove the letters (<code>A</code>, <code>B</code>, <code>A and B</code>, …) in the fourth column (<code>v1</code>), and then split the fourth column into multiple columns just like this:</p>
  
  <pre><code>  subject sex age x1 x2 x3 x4 x5 x6
  1       1   1  35  0  1  0  0  0  0        
  2       2   2  29  0  0  0  0  0  0
  3       3   2  31  0  0  1  0  1  0  
  4       4   1  46  1  1  0  0  0  0
  5       5   2  64  0  0  0  1  0  0
  6       6   1  57  1  0  0  0  0  0
  7       7   1  49  0  0  1  0  0  0
  8       8   2  58  0  0  0  0  1  1
  </code></pre>
  
  <p>where the 1st subject takes 1 at x2 because it takes 2 at v1 in the original dataset, the 3rd subject takes 1 at both x3 and x5 because it takes 3 and 5 at v1 in the original dataset, and so on.</p>
  
  <p>I would appreciate any help on this question. Thanks a lot.</p>