title: Finding which element of a vector is between two values in R
body: <p>I have two vectors <code>x</code> and <code>y</code>. I would like to find which elements of <code>x</code> are between the two elements of vector <code>y</code>. How can I do it in R?</p>
  
  <pre><code>x = c( .2, .4, 2.1, 5.3, 6.7, 10.5)
  y = c( 1, 7)
  </code></pre>
  
  <p>I have written the following code, but it does not give me the correct result. </p>
  
  <pre><code>&gt; x = x[ x &gt;= y[1] &amp;&amp; x &lt;= y[2]]
  &gt; x
  numeric(0)
  </code></pre>
  
  <p>Result should be like this:</p>
  
  <pre><code>res = c(2.1, 5.3, 6.7)
  </code></pre>