title: dplyr::mutate:- new column = difference between two comma-delimited list columns
body: <p>Example that works:  </p>
  
  <pre><code>df &lt;- data.frame(c0=c(1, 2), c1=c("A,B,C", "D,E,F"), c2=c("B,C", "D,E"))
  df
  #   c0    c1  c2
  # 1  1 A,B,C B,C
  # 2  2 D,E,F D,E
  
  # Add a column d with difference between c1 and c2
  df %&gt;% mutate(d=setdiff(unlist(strsplit(as.character(c1), ",")), unlist(strsplit(as.character(c2), ","))))
  
  #   c0    c1  c2 d
  # 1  1 A,B,C B,C A
  # 2  2 D,E,F D,E F
  </code></pre>
  
  <p>I get what I expected above: d is assigned the difference between these two lists of characters (they are already sorted).</p>
  
  <p>However, if I introduce more than one different character it no longer works:</p>
  
  <pre><code>df &lt;- data.frame(c0=c(1, 2), c1=c("A,B,C", "D,E,F,G"), c2=c("B,C", "D,E"))
  df
  #   c0      c1  c2
  # 1  1   A,B,C B,C
  # 2  2 D,E,F,G D,E
  
  # Add a column d with difference between c1 and c2
  df %&gt;% mutate(d=setdiff(unlist(strsplit(as.character(c1), ",")), unlist(strsplit(as.character(c2), ","))))
  Error: wrong result size (3), expected 2 or 1
  </code></pre>
  
  <p>What I wanted to get there is:</p>
  
  <pre><code>  c0    c1    c2  d
  1  1 A,B,C    B,C A
  2  2 D,E,F,G  D,E F,G
  </code></pre>
  
  <p>I've tried adding a <code>paste()</code> around setdiff but that didn't help. In the end I actually want to be able to probably use <code>tidyr::separate</code> to split out the d column into new rows like:</p>
  
  <pre><code>  c0    c1    c2  d
  1  1 A,B,C    B,C A
  2  2 D,E,F,G  D,E F
  3  2 D,E,F,G  D,E G
  </code></pre>
  
  <p>What am I doing wrong with the setdiff above?</p>
  
  <p>Thanks</p>
  
  <p>Tim</p>