title: R compare multiple values with vector and return vector
body: <p>I have a vector "A", and for each element of A I want to check whether it is equal to any element from a second vector "Targets". I want a vector of logical values with the length of A as return. </p>
  
  <p>The same problem is mentioned <a href="http://r.789695.n4.nabble.com/compare-multiple-values-with-vector-and-return-vector-td1749724.html" rel="nofollow noreferrer">here</a>. Here is a related discussion of <a href="https://stackoverflow.com/questions/1169248/r-function-for-testing-if-a-vector-contains-a-given-element">how to test if a vector contains a specific value</a>, but I did not know how to apply this to my question because I want a vector as output and not a single boolean. </p>
  
  <p>Here is example code: </p>
  
  <pre><code>#example data
  A &lt;- c(rep("A",4),rep(c("B","C"),8))
  Targets &lt;- c("A","C","D")
  </code></pre>
  
  <p>I would like a vector which tells me for each element of A if it is equal to at least one of the elements in Targets. For the example, this should produce a vector that is identical with:</p>
  
  <pre><code>result &lt;- c(rep("TRUE",4), rep(c("FALSE","TRUE"), 8))
  </code></pre>
  
  <p>In case this is relevant, eventually vector A will be much longer (ca 20000 elements), and the vector Targets will contain approximately 30 elements.</p>