title: Paste symbol in a sequence of characters by condition
body: <p>I have a vector <code>chars</code> of some characters: </p>
  
  <pre class="lang-r prettyprint-override"><code>chars &lt;- c("check24  smavey  dr klein", "smava", "check24, interhyp", 
    "verivox  check24  dr. klein", "dr. klein", NA, "dr. weber", 
    "dr. klein,", NA, "check24  verivox")
  </code></pre>
  
  <p>The goal is to paste/insert "_" if they have white space between them and fulfill the following conditions: </p>
  
  <ol>
  <li>There is no comma between the sequence (e.g. <code>Name1, Name2 Name3</code> should become <code>Name1, Name2_Name3</code>).</li>
  <li>There is no point between them (e.g. <code>Dr. Name1 Name2 Name3</code> should become <code>Dr. Name1_Name2_Name3</code>).</li>
  <li>The length between the whitespace is and the charcter sequence is >= 4 on both sides (e.g. <code>AAA AAAA AAAA AAAA</code> should become <code>AA AAAA_AAAA_AAAA</code>).</li>
  </ol>
  
  <p>I tried using this function:</p>
  
  <pre class="lang-r prettyprint-override"><code>library(stringr)
  
  f = function(x) {
    ifelse(grepl(".{4} .{4}", x) &amp; !grepl(",|[A-z]{2}/. ", x), str_replace_all(x, "\\s+", "_"), x)
  }
  
  f(chars)
  #&gt; [1] "check24_smavey_dr_klein"   "smava"                     "check24, interhyp"         "verivox_check24_dr._klein"
  #&gt; [5] "dr. klein"                 NA                          "dr. weber"                 "dr. klein,"               
  #&gt; [9] NA                          "check24_verivox"        
  </code></pre>
  
  <p>The problem is that I can't execute the cases in a sequence (e.g. <code>[1]</code> or <code>[4]</code>)</p>
  
  <p>Any idea how to do this? </p>