title: struggling to apply a function to a column and create a new column
body: <p>I have a table in R which has a column containing a string value which i need to tokenenize into 4 separate columns which would have a 0 or 1 in them depending on whether a token was present. For example</p>
  <p>a,b,c,d are all the tokens</p>
  <p>a column could have any permutation of the tokens in a string e.g.</p>
  <p>a,c
  b,d
  c,a</p>
  <p>what i want is to turn</p>
  <pre><code>  combind
  1   A,B,C
  2       A
  3     A,B
  4     B,C
  </code></pre>
  <p>into</p>
  <pre><code>  combind A B C
  1   A,B,C 1 1 1
  2       A 1 0 0
  3     A,B 1 1 0
  4     B,C 0 1 1
  </code></pre>
  <p>Be gentle with me as i am very new to R and its making me very angry at the moment !</p>
  <p>I have tried all sorts of approaches to iterate through the first table to apply a function to the first column to get the values for the second column and add them in using the data.table library</p>
  <p>e.g</p>
  <pre><code>df[,AValPre := isAPresent(combind)]
  </code></pre>
  <p>where isAPresent is a function with an grepl</p>
  <pre><code>printf &lt;- function(...) invisible(print(sprintf(...)))
  
  ## Setup functions for extraction of the location
  containsA &lt;- function(str) {
    
    cond &lt;- grepl(&quot;A&quot;, str)
    
    if (cond[1] == TRUE)
      rv &lt;- 1
    else
      rv &lt;- 0
    printf(&quot;Checking A in [%s] cond %d rv %d&quot;,str, cond, rv)
    
    return (rv)
  }
  </code></pre>
  <p>Help I am at my complete wits end with this....</p>