title: R: Using position information of elements  when looping through a vector.
body: <p>When looping through a vector, is it possible to use the index of an element along with the element?</p>
  
  <p>a.vector&lt;-c("a", "b", "c", "a", "d")</p>
  
  <p>Let's suppose I need the index of the 'first' "a" of a.vector. 
  One can't use </p>
  
  <blockquote>
    <p>which(a.vector == "a")</p>
  </blockquote>
  
  <p>Because there are two 'a' s and it would return two positions 1 and 4. I need the specific index of the element which the loop is instantly covering. </p>
  
  <p>I need it for something like this:</p>
  
  <p>b.vector&lt;-c("the", "cat", "chased", "a", "mouse")</p>
  
  <pre><code>for (i in a.vector) {
      element&lt;-b.vector[INDEX.OF(a.vector)])
  -------some process using both 'element' and "a"-------}
  </code></pre>
  
  <p>This seems similar to the 'enumerate' function in python. A solution would help a lot. Thanks.</p>