title: Find matching indices for pattern vector in grep
body: <p>Is there an easy way to find corresponding vector indices when working with <code>grep</code>? </p>
  
  <pre><code>v=c(123,456,789,651)
  pat=c(1,35,47,8)
  id=grep(paste0(pat, collapse="|"), v)
  v[id]
  
  [1] 123 789 651
  </code></pre>
  
  <p>I would like to generate: </p>
  
  <pre><code>pat_id
  [1] 1 4 1
  </code></pre>
  
  <p>So that <code>pat[pat_id]</code> would give me the values in <code>pat</code> that matched. </p>
  
  <pre><code>pat[pat_id]
  [1] 1 8 1
  </code></pre>
  
  <p><code>match()</code> cannot be used in this case because strings have to be identical to count as a match. </p>