title: R efficient way to sort a Matrix by row
body: <p>I have a matrix "multiOrderPairsFlat" of 2m+ rows and 2 columns where each cell contains a SKU description (e.g. "Pipe2mSteel" or "Bushing1inS") and would like to sort every row alphabetically, so that in every row, e.g. "Bushings1inS" is in the first column and "Pipe2mSteel" in the second.</p>
  
  <p>However, if I run:</p>
  
  <pre><code>for (i in 1:length(multiOrderPairsFlat)){
    multiOrderPairsFlat[i,] &lt;- sort(multiOrderPairsFlat[i,])
  }
  </code></pre>
  
  <p>It takes forever and I doubt this is the quickest way of dealing with this problem. Do you have any advice on how to solve this more efficiently, e.g. by vectorizing the operation? </p>
  
  <p>Thanks for helping out;)
  Best
  seulberg1</p>