title: Matching matrix rows with list elements in R
body: <p>A reproducible data:</p>
  <pre><code>dat1 &lt;- matrix(0, nrow = 9, ncol = 2)
  dat1[,1] &lt;- rep(1:3,3)
  dat1[,2] &lt;- c(1,1,1,2,2,2,3,3,3)
  
  dat2 &lt;- list()
  dat2[[1]] &lt;- matrix(c(1,2,1,3), nrow = 2, ncol = 2)
  dat2[[2]] &lt;- matrix(c(1,1,2,3,1,3), nrow = 3, ncol = 2 )
  
  &gt; dat1
        [,1] [,2]
   [1,]    1    1
   [2,]    2    1
   [3,]    3    1
   [4,]    1    2
   [5,]    2    2
   [6,]    3    2
   [7,]    1    3
   [8,]    2    3
   [9,]    3    3
  
  &gt; dat2
  [[1]]
       [,1] [,2]
  [1,]    1    1
  [2,]    2    3
  
  [[2]]
       [,1] [,2]
  [1,]    1    3
  [2,]    1    1
  [3,]    2    3
  </code></pre>
  <p>I have a matrix (dat1) and a list (dat2).</p>
  <p>Some rows of dat1 is same as some of the list elements of dat2. My objective is to find out the corresponding row numbers of dat1 that are matched with dat2 and store them in a list. AN EXAMPLE of the output:</p>
  <pre><code>&gt; ex.result
  [[1]]
       [,1]
  [1,]    1
  [2,]    8
  
  [[2]]
       [,1]
  [1,]    7
  [2,]    1
  [3,]    8
  </code></pre>
  <p>I am looking for a fast way to do this without using time consuming loops.</p>