title: How to obtain a factor variable according to two columns. R
body: <p>I nee to create a new column <code>v4</code> in this data.frame:</p>
  
  <pre><code>v1&lt;-c(1,2,4,7,9,12,34,56,43)
  v2&lt;-c(4,4,9,56,73,457,12,12,5585)
  v3&lt;-c(7,7,43,124,415,552,552,12525,99)
  df&lt;- data.frame(v1,v2,v3)
  </code></pre>
  
  <p>The trick is that in those cases where any of the <code>v1</code> value is present in <code>v2</code> <code>v4</code> must be <code>1</code> rest of the cases <code>v4</code> must be <code>2</code></p>
  
  <p>So the outcome would be something like this:</p>
  
  <pre><code>v1&lt;-c(1,2,4,7,9,12,34,56,43)
  v2&lt;-c(4,4,9,56,73,457,12,12,5585)
  v3&lt;-c(7,7,43,124,415,552,552,12525,99)
  v4&lt;-c(2,2,1,2,1,1,2,2,2)
  df.solution&lt;- data.frame(v1,v2,v3,v4)
  </code></pre>