title: Find the index of subset data frame from its original data frame in R
body: <p>I have a data frame in R, say a1 here for a toy example, and I have a row subset from it, say a2.
  I want to find the original subset index (2,4).</p>
  <p>I tried  <em>which</em>  or <em>match</em>, but did not succeed.</p>
  <pre><code> set.seed(123)
   a1=data.frame(x1=rnorm(5),x2=runif(5),x3=runif(5))
   a2=a1[c(2,4),]
   a2index=rep(NA,dim(a2)[1])
  </code></pre>
  <p>Here is my a1 data.frame</p>
  <pre><code>    a1
             x1        x2         x3
  1 -0.56047565 0.9568333 0.89982497
  2 -0.23017749 0.4533342 0.24608773
  3  1.55870831 0.6775706 0.04205953
  4  0.07050839 0.5726334 0.32792072
  5  0.12928774 0.1029247 0.95450365
  </code></pre>
  <p>a2 is a row subset of a1:</p>
  <pre><code> a2
             x1        x2        x3
  2 -0.23017749 0.4533342 0.2460877
  4  0.07050839 0.5726334 0.3279207
  </code></pre>
  <p>I managed to obtain the index using double loop. But it is too slow, is there a way to speed it up?</p>
  <p>Thanks for help.</p>
  <pre><code>for (i in 1:dim(a2)[1] )
     for (j in 1:dim(a1)[1])
       if (all(a2[i,]==a1[j,])){
         a2index[i]=j
         break;
         } 
  
  # return the index vector (2,4) 
  a2index``
  </code></pre>