Trying to write a function to sort a matrix by rows. I could write something to loop over the values on a vector of values but couldn't add complexity to make it loop over some matrix.
sww = function(x){
  n <- length(x)
      for(i in 1:(n-1)){
         for (j in (i+1):n) {
        if(x[i] > x[j]){
          tmp = x[i]; x[i] = x[j]; x[j] = tmp
          }
        }
      }
  return(x)
}
does anyone knows how to make it loop over an entire matrix ?
Edit:
By sorting a matrix by rows I meant to have a matrix like:
2 1 4    "Sorted by row"     1 2 4
5 4 0          -->           0 4 5
Thank you
Edit1: I know about the r functions but would like to write my own
 
    