title: Replace multiple strings in one gsub() or chartr() statement in R?
body: <p>I have a string variable containing alphabet[a-z], space[ ], and apostrophe['],eg. <code>x &lt;- "a'b c"</code>
  I want to replace apostrophe['] with blank[], and replace space[ ] with underscore[_].</p>
  
  <pre><code>x &lt;- gsub("'", "", x)
  x &lt;- gsub(" ", "_", x)
  </code></pre>
  
  <p>It works absolutely, but when I have a lot of condition, the code becomes ugly. Therefore, I want to use <code>chartr()</code>, but <code>chartr()</code> can't deal with blank, eg.</p>
  
  <pre><code>x &lt;- chartr("' ", "_", x) 
  #Error in chartr("' ", "_", "a'b c") : 'old' is longer than 'new'
  </code></pre>
  
  <p>Is there any way to solve this problem? thanks!</p>