title: How to get combinations of two factors and convert into a new factor in R
body: <p>For example, I can do something like this:</p>
  
  <pre><code>x = c(1, 2, 3, 3, 2, 1)
  y = c(rep("a", 3), rep("b", 3))
  z= ifelse(x==1 &amp; y=="a", "a1", ifelse(x==1 &amp; y=="b", "b1", ifelse(x==2 &amp; y=="a", "a2", ifelse(x==2 &amp; y=="b", "b2", ifelse(x==3 &amp; y=="a", "a3", "b3")))))
  z = factor(z)
  </code></pre>
  
  <p>But this is tedious,  is there a better way?</p>