title: how to deal with if statement in for loop in R
body: <pre><code>a &lt;- c("CA", "ON", "TX", "FL", "CO")
  b &lt;- c("CA", "ON", "TX", "FL", "CO", "AB", "IL", "NY", "WA")
  </code></pre>
  
  <p>I want to compare a and b, and change "AB" "IL" "NY" and "WA" to "other". something likes this,</p>
  
  <pre><code> b &lt;- c("CA", "ON", "TX", "FL", "CO", "other", "other", "other", "other")
  </code></pre>
  
  <p>This is only a sample, the original dataset is huge, I need to do it in an easy way.</p>