Rearrange rows and columns of a matrix by dim names
sortByDimnames(x, row.decreasing = FALSE, col.decreasing = FALSE)
Resorted matrix or data frame
testMat <- matrix(1:16, nrow=4, dimnames=list(c("B", "D", "A", "C"), c("t", "f", "a", "g")))
sortByDimnames(testMat)
#> a f g t
#> A 11 7 15 3
#> B 9 5 13 1
#> C 12 8 16 4
#> D 10 6 14 2
sortByDimnames(testMat, row.decreasing=TRUE, col.decreasing=FALSE)
#> a f g t
#> D 10 6 14 2
#> C 12 8 16 4
#> B 9 5 13 1
#> A 11 7 15 3