title: In R, match function for rows or columns of matrix
body: <p>The <a href="http://stat.ethz.ch/R-manual/R-patched/library/base/html/match.html" rel="noreferrer">value matching function</a> in <code>R</code> is very useful. But from my understanding, it does not sufficiently support two or high dimensional inputs.  </p>
  
  <p>For example, assume <code>x</code> and <code>y</code> are matrices of same number of columns, and I would like to match rows of <code>x</code> to rows of <code>y</code>. The 'R' function call <code>match(x,y)</code> does not do so. The same insufficiency occurs to inputs of lists.  </p>
  
  <p>I have implemented my own version of it called <code>matchMat(xMat, yMat)</code> (attached below), but I am wondering what is you solution to this task. </p>
  
  <pre><code>matchMat = function(xMat, uMat, dimn=1) {
      ind = rep(-1, dim(xMat)[dimn])
      id = 1 : dim(uMat)[dimn]
      for (i in id) {
          e = utilSubMat(i, uMat, dimn)
          isMatch = matchVect(e, xMat, dimn)
          ind[isMatch] = i
      }
      return(ind)
  }
  
  matchVect = function(v, xMat, dimn) {
      apply(xMat, dimn, function(e) {
          tf = e == v
          all(tf)
      })
  }
  
  unittest_matchMat = function() {
      dimn = 1
      uMat = matrix(c(1, 2, 2, 3, 3, 4, 4, 5), ncol=2, byrow=T)
      ind = sample(dim(uMat)[1], 10, replace=T)
      print(ind)
      xMat = uMat[ind, ]
      rst = matchMat(xMat, uMat, dimn)
      print(rst)
      stopifnot(all(ind == rst))
  
      xMat2 = rbind(c(999, 999), xMat, c(888, 888))
      rst2 = matchMat(xMat2, uMat, dimn)
      print(rst2)
      stopifnot(all(c(-1, ind, -1) == rst2))
      print('pass!')   
  }
  </code></pre>