title: How can I put my for-loop in dplyr::mutate( )? [tidyverse]
body: <p>I've got a <code>for-loop</code> that corrects misspellings in strings (actually it changes closely spelled strings to be identical). </p>
  
  <p>As I typically use <code>dplyr</code>'s functions and have long code sequences of many changes, I'd like to have a <code>dplyr</code>-friendly way to use my <code>for-loop</code> within a <code>mutate</code> call. </p>
  
  <p>Here's an example.</p>
  
  <pre><code>name &lt;-  c('pat','paet','Pat', 'bob',
       'beb','bab')
  name
  [1] "pat"  "paet" "Pat"  "bob"  "beb"  "bab"
  
  for ( i in seq_along(name)){
  
    name &lt;- ifelse(agrepl(name[[i]],name),name[[i]],name)
  
  }
  
  name
   [1] "pat" "pat" "pat" "bob" "bob" "bob"
  </code></pre>
  
  <p>I'd like to get the results above when using a <code>dplyr</code>/<code>data_frame</code> approach.</p>
  
  <pre><code>df &lt;- data_frame(name_ii =  c('pat',
           'paet',
           'Pat',
           'bob',
           'beb',
           'bab'))
  df %&gt;% 
  mutate(name = name_ii,
         name = for ( i in seq_along(name)){
  
    name &lt;- ifelse(agrepl(name[[i]],name),name[[i]],name)
  
  }
  )
  
  Error in mutate_impl(.data, dots) : Binding not found: name_ii.
  </code></pre>
  
  <p>I've attempted to put it into a user-defined function called <code>identicator</code>.</p>
  
  <pre><code>identicator &lt;- function(x){
  name &lt;- x
  
  for ( i in seq_along(name)){
  
        name &lt;- ifelse(agrepl(name[[i]],name),name[[i]],name)
  
      }
  }
  
    df %&gt;% 
      mutate(new.name = identicator(x))
  
  Error in mutate_impl(.data, dots) : 
    Column `d` is of unsupported type NULL
  </code></pre>
  
  <p>Thanks</p>