title: R Test if Lists Contain String
body: <p>I have a string of numbers, and a list: </p>
  
  <pre><code> a &lt;- c(1,2,3)
   b &lt;- list( x&lt;-c(1:5),y&lt;-c(1:10),z&lt;-c(10:20))
  </code></pre>
  
  <p>What I want to do is to test whether each number is in each element of the list -- whether 1 is in x, 2 is in y, 3 is in z. And then give 1/0 to a new variable. </p>
  
  <p>My code:</p>
  
  <pre><code>d &lt;- ifelse(a %in% sapply(b,function(x) unlist(x)),1,0)
  </code></pre>
  
  <p>However the result:</p>
  
  <pre><code>&gt; d
  [1] 0 0 0
  </code></pre>
  
  <p>And desirable result should be: </p>
  
  <pre><code>[1] 1 1 0
  </code></pre>
  
  <p>How can I do this? Thank you</p>