Matrix

order a matrix by a pre-defined group and then by the rowSums in R

I will lay down the R code below