title: Get first n indexes fulfilling a condition in r
body: <p>I have a large vector where I have different values. I would like to find first N values which are less than a particular value.</p>
  
  <p>For example in the following vector I want only 3 indexes which are less than 3</p>
  
  <pre><code>x2 &lt;- c(1.6,0.35,1,3,6,8,1.5,2)
  x3 &lt;- which(x2 &lt; 3)
  x3
  [1] 1 2 3 7 8
  </code></pre>
  
  <p>From X3 I can extract the first three values but they are not the smallest values in the vector. If I order the X2 vector before applying the condition, I am loosing the indexes of the values. What I want at the end is as follows</p>
  
  <pre><code>[1] 2 3 7
  </code></pre>