title: Search a matrix for rows with given values in any order
body: <p>I have a matrix and a vector with values:</p>
  
  <pre><code>mat&lt;-matrix(c(1,1,6,
                3,5,2,
                1,6,5,
                2,2,7,
                8,6,1),nrow=5,ncol=3,byrow=T)
  
  vec&lt;-c(1,6)
  </code></pre>
  
  <p>This is a small subset of a N by N matrix and 1 by N vector. Is there a way so that I can subset the rows with values in vec?</p>
  
  <p>The most straight forward way of doing this that I know of would be to use the subset function:</p>
  
  <pre><code>subset(mat,vec[,1] == 1 &amp; vec[,2] == 6) #etc etc
  </code></pre>
  
  <p>The problem with subset is you have to specify in advance the column to look for and the specific combination to do for. The problem I am facing is structured in a way such that I want to find all rows containing the numbers in "vec" in any possible way. So in the above example, I want to get a return matrix of:</p>
  
  <pre><code>1,1,6
  1,6,5
  8,6,1
  </code></pre>
  
  <p>Any ideas?</p>