title: R: count number of different values of 2 factor vectors
body: <p>I have two vectors with the same length -- both are factors. I want to compare them position by position to see how many of are different. For example</p>
  
  <pre><code>&gt; a = as.factor(c(1,2,2,1,2,2,1))
  &gt; b = as.factor(c(1,2,1,1,1,2,1))
  </code></pre>
  
  <p>Since there are two different values at position 3 and position 5, I'd like to get 2 as the final results. I know I can convert them to numeric numbers and do a subtraction, but what if the value are strings, e.g.</p>
  
  <pre><code>a = as.factor(c("a","a","b"))
  b = as.factor(c("a","b","b"))
  </code></pre>
  
  <p>Are there any elegant, general ways to do this?</p>